【发布时间】:2020-05-10 07:00:09
【问题描述】:
我的 Angular 项目中的 setInterval() 有问题
这是我的代码
recordingTimer: any = '00:00:00';
timer: boolean = true;
recording(){
////// please type recording meeting functionality here
if (this.timer) {
let seconds = 0;
let minutes = 0;
let hours = 0;
seconds += 1;
if (seconds >= 60) {
seconds = 0;
minutes += 1
if (minutes >= 60) {
minutes = 0;
hours += 1
}
}
/// update recording time
this.recordingTimer = (hours ? (hours > 9 ? hours : "0" + hours) : "00") + ":" + (minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") + ":" + (seconds > 9 ? seconds : "0" + seconds);
console.log(this.recordingTimer)
}
}
repeat() {
setInterval(() => this.recording(), 1000);
}
为什么 console.log 语句重复但具有相同的值“00:00:01”
请帮忙,谢谢。
【问题讨论】:
标签: javascript angular typescript timer frontend