Open In App

Angular Material Progress Bar

Angular Material is a User Interface (UI) library of a set of components for AngularJS developers. It consists of a number of high-quality, internationalized, reusable, and accessible components for developers. This library contains pre-developed components and elements which can be directly used to accomplish any functionality.

The Progress Bar is a component provided by the Angular Material library, that is used to indicate the progress in the activity or show the status of any specific job, i.e. it tells the user how much task has been completed in the form of a linear. For creating a Progress bar, we can use the <mat-progress-bar> tag. There are 4 different modes in Progress Bar, which are described below:



Syntax:

<mat-progress-bar mode="" value=""></mat-progress-bar>

Installation Syntax: The main pre-requisite to work with Angular Material modules is to install Angular CLI in our system so that we can use the Angular Material UI library and its components. You can use the below command to install Angular CLI:



ng add @angular/material

Please refer to the Adding Angular Material Component to Angular Application article for the detailed installation procedure.

Adding Progress Bar component: To allow the use of the Progress Bar component, we need to import it in the app.module.ts file, then we need to add the “MatProgressBarModule” component into the “@NgModule” imports array.

import {MatProgressBarModule} from '@angular/material/progress-bar';

Creating Angular application & Module Installation:

ng new foldername
cd foldername
ng add @angular/material   

Project Structure: The project structure will look like the following:

Project Structure

Example 1: This example illustrates the basic use of the Angular Material Progress Bar by implementing the determinate mode. Here, we will use the “MatProgressBarModule” component.




import { NgModule } from '@angular/core';
import { BrowserModule }
    from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { MatProgressBarModule }
    from '@angular/material/progress-bar';
 
@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        MatProgressBarModule,
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule { }




<div style="width: 450px;
            text-align:center">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h4>
        Angular Material Determinate
        Progress Bar
    </h4>
    <mat-progress-bar mode="determinate"
                      value="40">
    </mat-progress-bar>
</div>




import { Component } from '@angular/core';
 
@Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    title = 'folderName';
}

Steps to run the program: To run the application execute the below command from the root directory of the project:

ng serve

Output: Your web application will be live on “http://localhost:4200”, as we can see from the following output:

 

Example 2: In this example, we will see progress-bar in “indeterminate” mode.




import { NgModule } from '@angular/core';
import { BrowserModule }
    from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { MatProgressBarModule }
    from '@angular/material/progress-bar';
 
@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        MatProgressBarModule,
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule { }




<div style="width: 450px;
            text-align:center">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h4>
        Angular Material Indeterminate
        Progress Bar
    </h4>
    <mat-progress-bar mode="indeterminate"
                      value="40">
    </mat-progress-bar>
</div>




import { Component } from '@angular/core';
 
@Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    title = 'folderName';
}

Output:

 

Example 3: In this example, we will see progress-bar in “buffer” mode.




import { NgModule } from '@angular/core';
import { BrowserModule }
    from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { MatProgressBarModule }
    from '@angular/material/progress-bar';
 
@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        MatProgressBarModule,
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule { }




<div style="width: 450px;
            text-align:center">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h4>
        Angular Material Buffer
        Progress Bar
    </h4>
    <mat-progress-bar mode="buffer">
    </mat-progress-bar>
</div>




import { Component } from '@angular/core';
 
@Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    title = 'folderName';
}

Output:

 

Example 4: In this example, we will see progress-bar in “query” mode.




import { NgModule } from '@angular/core';
import { BrowserModule }
    from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { MatProgressBarModule }
    from '@angular/material/progress-bar';
 
@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        MatProgressBarModule,
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule { }




<div style="width: 450px;
            text-align:center">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h4>
        Angular Material Buffer
        Progress Bar
    </h4>
    <mat-progress-bar mode="buffer">
    </mat-progress-bar>
</div>




import { Component } from '@angular/core';
 
@Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    title = 'folderName';
}

Output:

 

Reference: https://material.angular.io/components/progress-bar/overview


Article Tags :