ionic-framework: Bug@Ionic 2 : nav.pop not work with ActionSheet and Alert
both ActionSheet and Alert handler not work with this.nav.pop()
constructor(nav: NavController) {
this.nav = nav;
}
presentActionSheet() {
let actionSheet = ActionSheet.create({
title: 'Leave this page',
buttons: [
{
text: 'Destructive',
style: 'destructive',
handler: () => {
this.nav.pop() //pop not work here!
}
},
{
text: 'Cancel',
style: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
this.nav.present(actionSheet);
}
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 22 (6 by maintainers)
Hello everyone! Thanks for opening an issue with us! The answer for this is to use promises. Our navigation system returns promises for all the nav methods (push(), pop(), present(), dismiss() etc etc) so the proper way to use nav.push() with an alert would be like this:
You can also check out this link and this link to read more about using promises with navigation in Ionic 2. Thanks for using Ionic!
@tejit2004 this should be fixed in next beta! we refactored the whole overlay system (alert, action sheet, modals) so it is not longer coupled with the navigation stack.
Please reopen this issue once the beta11 is released and you consider this issue was not fixed 😃
@kz with the overlay component refactor that is coming in beta.11 you will not have to always dismiss the actionsheet before opening an alert. Hope that answers you question!
Am I correct that this issue is also to do with Alert buttons not working after opening Alert in an ActionSheet in Beta 10? I managed to fix this issue by asynchronously dismissing the ActionSheet before creating the Alert, which seems to be the solution in this issue. Either way, in future versions, is the accepted practice to always dismiss the ActionSheet first before opening the Alert in the ActionSheet’s handler, or should I leave it for Ionic to handle this and directly create an Alert under an ActionSheet handler (which caused this bug)?