I navigate from a view detail to a edit detail screen by a push command.
When I go back by the nav button, i want to get an alert with a question that when the user go back, he loses the changes. That works at the moment.
But when I choose OK and go back to lose my changes, I will get the newest data of the object from the database but that takes more time and he goes back before my request is done.
Can anyone give me info how to solve this?
Can I do a synchronous call that he goes back when the getAnimal http request is ready?
I didn’t find a topic that can help me.
This helped me a little bit http://stackoverflow.com/questions/37955114/alert-before-leaving-page-navigate-back-with-ionic-v2
If my question is not clear or the context, feel free to ask more details.
Thanks in advance!
ionViewCanLeave(): Promise<void>{
console.log("ionViewCanLeave");
return new Promise((resolve, reject) => {
let confirm = this.alertCtrl.create({
title: 'Are you sure?',
message: 'If you go back, you lose the changes',
buttons: [{
text: 'OK',
handler: () => {
let loader = this.loadingCtrl.create();
loader.present();
this.animalService.getAnimal(this.animal).subscribe(
data => {
this.animal = data;
},
err => {
console.log(err);
},
() => {
loader.dismiss();
resolve();
}
);
},
}, {
text: 'Cancel',
handler: () => {
reject();
}
}],
});
confirm.present();
})
}