app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
isDisable:boolean = false;
progress:number = 0;
timer:any;
maxValue:number = 20;
percentage:number = 0;
onClick(){
this.progress = 0;
this.isDisable = true;
this.timer = setInterval(() => this.updateProgress(), 1000)
}
updateProgress(){
this.progress++
if(this.progress>=this.maxValue){
clearInterval(this.timer);
this.isDisable = false;
}
this.calculatePercentage()
}
calculatePercentage(){
//this.percentage = Math.round((this.progress / this.maxValue) * 100);
//this.percentage = Math.ceil((this.progress / this.maxValue) * 100);
this.percentage = Math.floor((this.progress / this.maxValue) * 100);
}
}
app.component.html
<h2 style="padding-top:25px; padding-bottom:25px;">
Angular Material - Progress bar with percentage
</h2>
<button
mat-raised-button
color="accent"
(click)="onClick()"
[disabled]="isDisable"
style="margin-bottom:30px;">
Run {{maxValue}} Task
</button>
<h3>{{'Task ' + progress + ' of ' + maxValue + ' done.'}}</h3>
<h3>{{'Done ' + percentage + '%'}}</h3>
<mat-progress-bar
mode="determinate"
[value]="percentage">
</mat-progress-bar>
app.module.ts [import]
import {MatProgressBarModule} from '@angular/material/progress-bar';
import {MatButtonModule} from '@angular/material/button'
- angular material - How to show vertical Divider
- angular material - How to use Progress bar
- angular material - How to use indeterminate Progress bar
- angular material - How to use buffer Progress bar
- angular - Display value using interpolation
- angular - How to use if else condition
- angular - Multiple condition
- angular - How to use nested loop
- angular - How to call function on Button click
- angular - How to generate random number
- angular bootstrap - How to show an alert
- angular bootstrap - Rating hover event
- angular bootstrap - How to show striped Progressbar
- angular bootstrap - Show custom label in Progressbar
- angular bootstrap - How to delay Popover open close