app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
isDisabled:boolean = false;
progress:number = 0;
timer:any;
maxValue:number = 50;
percentage:number = 0;
onClick(){
this.progress = 0;
this.isDisabled = true;
this.timer = setInterval(() => this.updateProgress(), 1000)
}
updateProgress(){
this.progress++
if(this.progress>=this.maxValue){
clearInterval(this.timer);
this.isDisabled = 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 - How to use indeterminate Progress bar
</h2>
<button
mat-flat-button
color="warn"
(click)="onClick()"
[disabled]="isDisabled"
style="margin-bottom:25px;">
Run {{maxValue}} Task
</button>
<h3>
{{
'Task ' + progress + ' of ' + maxValue + ' done.'
+ ' ( '+ percentage + '% done. )'
}}
</h3>
<mat-progress-bar
mode="indeterminate"
*ngIf="isDisabled">
</mat-progress-bar>
app.module.ts [import]
import {MatProgressBarModule} from '@angular/material/progress-bar';
import {MatButtonModule} from '@angular/material/button'
- angular material - How to set Tooltip show hide delay
- angular material - How to enable disable Tooltip
- angular material - How to show vertical Divider
- angular material - How to use Progress bar
- angular material - Progress bar with percentage
- angular material - How to use buffer Progress bar
- angular bootstrap - Timepicker with meridian
- angular bootstrap - Datepicker navigate to current month
- angular bootstrap - Datepicker navigate & select today
- angular bootstrap - Select date range from Datepicker popup
- angular bootstrap - How to use Accordion
- angular bootstrap - How to prevent toggle Accordion panel
- angular bootstrap - How to show vertical pills in a Nav
- angular material - How to use raised Button
- angular material - How to use Button toggle