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 = 500;
percentage:number = 0;
onClick(){
this.progress = 0;
this.isDisable = true;
this.timer = setInterval(() => this.updateProgress(), 100)
}
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 - Percentage in determinate Progress bar
</h2>
<button
mat-raised-button
color="primary"
(click)="onClick()"
[disabled]="isDisable"
style="margin-bottom:30px;">
Run {{maxValue}} Tasks
</button>
<h3>{{
'Task ' + progress + ' of ' + maxValue + ' done.'
+ ' ( Done ' + percentage + '% )'
}}
</h3>
<mat-progress-bar
mode="determinate"
[value]="percentage"
color="primary">
</mat-progress-bar>
app.module.ts [import]
import {MatProgressBarModule} from '@angular/material/progress-bar';
import {MatButtonModule} from '@angular/material/button'
- angular material - How to use query Progress bar
- angular - How to change default font
- angular - How to do a task after a delay
- angular - How to use setInterval()
- angular material - How to change Progress bar height
- angular material - How to change Divider color
- angular material - How to change Progress bar width
- angular material - How to change vertical Divider height
- angular material - How to change Divider margin
- angular material - How to use Progress spinner
- angular material - How to use determinate Progress spinner
- angular material - Progress spinner with percentage
- angular material - How to change Progress spinner size
- angular material - How to use Tabs
- angular material - How to use custom label in Tabs