【发布时间】:2021-04-23 07:00:42
【问题描述】:
有一个通知动画,当单击关闭按钮时,我会显示一个类似弹出窗口的关闭(反向动画)。如果有另一个通知,它会等待 1.5s 并播放动画。
我正在使用带有承诺的 async/Await。这件事似乎不起作用。它会立即执行,因此我不播放动画。
这是我的打字稿代码
async waitAsync() {
return new Promise<boolean>((resolve, reject)=> {delay(1500); resolve(true);});
}
// called on close button click
toggleNotif() {
this.hide = true;
this.animateWithdraw = true;
this.toggleAnimation();
this.currentIdx++;
this.checkForNextAlert();
}
// checks for new notification and plays the animation consequently.
checkForNextAlert() {
if (this.currentIdx < this.maxProjToAlert) {
console.log(this.projectsToAlert[this.currentIdx].name);
this.setAlertMsg(this.projectsToAlert[this.currentIdx].name);
(async()=> {
const val = await this.waitAsync();
this.animateWithdraw = false;
this.toggleAnimation();
})();
// tslint:disable-next-line:no-console
// this.animateWithdraw = await NotificationComponent.waitFunction();
// tslint:disable-next-line:no-console
}
}
// Affects some CSS class so the css3 animation gets played.
toggleAnimation():string {
if(!this.animateWithdraw) {
return 'notif notifAnimate';
}
return 'notif notifWithdraw';
}
【问题讨论】:
标签: angular typescript async-await