Dear All,
I want to prompt the user that changes will be discarded if he leaves the page. Please see code below.
ionViewCanLeave(): Promise<boolean> {
// apply only when going backward
if (this.moveBack) {
return new Promise((resolve: any, reject: any) => {
let alert = this.alertCtrl.create({
title: 'Warning',
message: 'Are you sure you want to leave this page? All changes made will be discarded.'
});
alert.addButton({
text: 'Stay',
handler: () => {
reject();
}
});
alert.addButton({
text: 'Leave',
role: 'cancel',
handler: () => {
//clear temp area for saving of return
this.SaveReturnService.clear();
resolve();
}
});
alert.present();
});
}
}
The prompt is displayed. If the users chooses stay, it is ok but if it chooses ‘leave’, there is strange behavior. For instance see below pages.
A -> B -> C
If i am on page B and choose to leave the page, it will pop to A and then to push C. Just wanted to know if there is anyone who has encountered this issue.
Thanks,
Ashley