Reputation:
i have this code and i want it to stop the countdown when the user clicks yes/ no in the alert message. i am new with ionic so i appreciate the help! thank you !
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);
}
Upvotes: 0
Views: 91
Reputation: 38922
In both buttons' handler, call clearInterval
passing the timer to stop the timer.
handler: () => {
console.log('NO, I am Okay');
clearInterval(this.timer)
}
Upvotes: 1