Я хочу посчитать время, когда я нажимаю кнопку. И что я делал до сих пор, так это отображал минуты и секунды, когда я нажимал кнопку.
Пример времени: 21 (мин): 02 (сек c)
Я хочу видеть, когда меняются минуты и секунды, но я не знаю, как это сделать.
ц.
startTime = false;
minutes: number;
seconds: number;
getTime() {
this.startTime = !this.startTime;
this.runTime();
setInterval(this.runTime, 1000);
}
runTime() {
this.todayDate = new Date();
this.minutes = this.todayDate.getMinutes();
console.log(this.minutes) /* here I can see in console that it prints minutes and seconds in real
time, but in the UI nothing happens, it appears only the date when I
click the button */
this.seconds = this.todayDate.getSeconds();
}
. html
<button type="button" class="btn btn-primary" (click)="getTime()">Time</button>
<div *ngIf="startTime">
Time: {{minutes}} : {{seconds}}
</div>
Не могли бы вы, пожалуйста, помочь мне с этим?