My setInterval() function seems to be working fine as the timer starts, but I am encountering an issue with clearInterval(). It does not stop the timer when the counter value reaches 100 and continues running continuously. Any help or suggestions would be greatly appreciated.
Here is the code for my component -
export class AppComponent {
counter=0;
progressInterval;
ngOnInit(){
this.progressInterval=setInterval(() => {
this.counter=this.counter + 10;
if(this.counter >= 100){
clearInterval(this.progressInterval);
}
},200);
}
}
Below is the HTML code for my component -
<p style="margin:20px;">
<ngb-progressbar
type="warning"
[value]="counter"
[striped]="true"
[animated]="true"
>{{counter}}</ngb-progressbar>
</p>
This screenshot displays the progress bar in action:
Screenshot
Thank you!