【发布时间】:2019-03-06 15:46:04
【问题描述】:
我在 angular2 中有一个应用程序,我必须在其中重现事件历史。
所以,当我按下 PLAY 按钮时,它必须从第一个事件开始,在那里停留 3 秒,然后转到下一个事件,再停留 3 秒,然后是下一个,依此类推。
事件列表是动态的。
关键是使用简单的setTimeOut 这不起作用,我想知道是否有其他方法可以解决我需要的问题。
我试过了:
play() {
if (this.history !== undefined) {
this.playMode = true;
const allEvents = this.history;
const historyLength = allEvents.length;
const progressInterval = 100 / historyLength;
allEvents.forEach(e => {
console.log(e);
setTimeout(t => {
this.progress += progressInterval;
}, 3000);
});
}
}
我需要 this.progress 变量以在 mat-progress-barr 中显示进度
<mat-progress-bar *ngIf="playMode" strokeWidth="0.5" mode="determinate" [value]="progress" color="accent"></mat-progress-bar>
显然我的代码不能按我的意愿运行。
我怎样才能做到“延迟”?
【问题讨论】:
标签: angular typescript angular-material settimeout delay