times = {
year: 31557600,
month: 2629746,
day: 86400,
hour: 3600,
minute: 60,
second: 1
}
timeLeft: number = 70;
interval;
m:number;
s:number;
startTimer() {
alert("start");
this.interval = setInterval(() => {
if(this.timeLeft > 0) {
this.timeLeft--;
} else {
this.timeLeft = 60;
}
this.m = Math.floor( this.timeLeft / 60);
this.s = this.timeLeft%60;
},1000)
}
pauseTimer() {
clearInterval(this.interval);
}
<button (click)='startTimer()'>Start Timer</button>
<button (click)='pauseTimer()'>Pause</button>
<p style="color: black;">{{timeLeft}} Seconds Left....</p>
<p style="color: black;">{{m}}:{{s}}</p>
No comments:
Post a Comment