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;
onClick(){
this.isDisabled = true;
// Repeat executing a function at a specified time interval.
setInterval(() => this.updateCounter(), 1000)
}
updateCounter(){
this.counter++;
}
}
app.component.html
<h2 style="padding-top:25px; padding-bottom:25px;">
Angular - How to use setInterval()
</h2>
<button
(click)="onClick()"
[disabled]="isDisabled"
style="margin-bottom:20px; padding:12px;">
Start Counting (1 second interval)
</button>
<h1>Counter : {{counter}}</h1>
- angular material - How to use query Progress bar
- angular material - Percentage in determinate Progress bar
- angular - How to change default font
- angular - How to do a task after a delay
- 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 use determinate Progress spinner
- angular material - Progress spinner with percentage
- angular material - How to change Progress spinner size
- angular material - How to slow Tabs content transition
- angular material - How to get Tabs selected index
- angular material - How to use Tabs selectedTabChange event
- angular material - How to show remove button on Tab label
- angular material - How to show Tab label bottom of content