app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
counter:number = 0;
isDisabled:boolean = false;
timer:any;
startCounting(){
this.counter = 0;
this.isDisabled = true;
// Repeat executing a function at a specified time interval.
this.timer = setInterval(() => this.updateCounter(), 1000)
}
stopCounting(){
clearInterval(this.timer);
this.isDisabled = false;
}
updateCounter(){
this.counter++;
}
}
app.component.html
<h2 style="padding-top:25px; padding-bottom:25px;">
Angular - How to use clearInterval()
</h2>
<button
(click)="startCounting()"
[disabled]="isDisabled"
style="margin-bottom:20px; padding:12px;">
Start Counting (1 second interval)
</button>
<button
(click)="stopCounting()"
[disabled]="!isDisabled"
style="margin-bottom:20px; padding:12px;">
Stop Counting
</button>
<h1>Counter : {{counter}}</h1>
- angular material - How to use query Progress bar
- angular material - Percentage in determinate Progress bar
- angular material - Show custom color in Progress bar
- 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 Card
- angular material - How to use Tabs
- angular material - How to use custom label in Tabs