A progress bar utilizes a basic percentage value ranging from 0
to 100
to determine the fill level of the bar. You can find more information about progress bars at this link.
To calculate and pass this percentage to <mat-progress-bar>
, create a method as shown below:
<mat-progress-bar mode="determinate" [value]="percent"></mat-progress-bar>
<br />
<br />
<button (click)="onStep(1)">next step</button>
<button (click)="onStep(-1)">previous step</button>
/**
* @title Determinate progress-bar
*/
@Component({
selector: 'progress-bar-determinate-example',
templateUrl: 'progress-bar-determinate-example.html',
})
export class ProgressBarDeterminateExample {
percent: number = 50;
maxSteps: number = 20;
currentStep: number = 10;
onStep(step: number) {
this.currentStep += step;
if (this.currentStep > this.maxSteps) {
this.currentStep = this.maxSteps;
} else if (this.currentStep < 0) {
this.currentStep = 0;
}
this.percent = (this.currentStep * 100) / this.maxSteps;
console.log(step);
console.log(this.percent);
}
}
For a live demonstration, refer to this working example: Link to StackBlitz