我有此代码,我希望当用户在警报消息中单击是/否时,它停止倒计时。 我是Ionic的新手,所以我感谢你的帮助! 谢谢 !
TS :
let alert = this.alertCtrl.create({
title: 'EMERGENCY ALERT!!!',
subTitle: 'Call Emergency Contact ?!',
buttons: [
{
text: 'NO, I am Okay',
handler: () => {
console.log('NO, I am Okay');
}
},
{
text: 'YES Call',
handler: () => {
console.log('YES Call');
}
}
],
enableBackdropDismiss: false
});
alert.present();
this.counter = 10;
window.clearInterval(this.timer);
this.timer = setInterval(() => {
this.counter--;
if (this.counter === 0) {
window.clearInterval(this.timer);
/*After counter value is 0 means 10000 is completed */
this.startFilling();
}
}, 1000);
}
startFilling() {
console.log(true);
}
在两个按钮的处理程序中,调用clearInterval
传递计时器以停止计时器。
handler: () => {
console.log('NO, I am Okay');
clearInterval(this.timer)
}