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 = 25;
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.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 spinner with percentage
</h2>
<button
mat-flat-button
color="primary"
(click)="onClick()"
[disabled]="isDisable"
style="margin-bottom:30px;">
Run {{maxValue}} Tasks
</button>
<div *ngIf="isDisable">
<h3>{{'Task ' + progress + ' of ' + maxValue + ' done.'}}</h3>
<h3>{{'Done ' + percentage + '%'}}</h3>
</div>
<mat-progress-spinner
mode="determinate"
[value]="percentage">
</mat-progress-spinner>
app.module.ts [import]
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner'
import {MatButtonModule} from '@angular/material/button'
- angular material - How to set Tooltip show hide delay
- angular material - How to enable disable Tooltip
- angular material - Show & hide Tooltip on button click
- angular material - How to show vertical Divider
- angular material - How to use Progress bar
- angular material - How to use query Progress bar
- angular material - Percentage in determinate Progress bar
- angular - How to use clearInterval()
- angular material - Show custom color in Progress bar
- angular material - How to change Divider width
- angular material - How to change Divider thickness
- angular material - How to use indeterminate Progress spinner
- angular - How to use setTimeout()
- angular material - How to use determinate Progress spinner
- angular material - How to change Progress spinner size