Search code examples
javascriptionic2angular2-template

how to close all ionic 2 modals?


I need to close all current modal popups and log out the user in ionic 2 application when the device goes to idle.

I used following methods to close popups in the home component.

this.viewController.dismiss().then(_ => {
  console.log("modal dismiss");
}).catch(error => {
  console.log(error)
});

and

this.navController.popAll().then(_ => {
  console.log("modal dismiss");
}).catch(error => {
 console.log(error);
})

But it throws following error You can't remove all pages in the navigation stack. nav.pop() is probably called too many times.

and does not close any popup. Anyone knows how to do it?


Solution

  • viewController.dismiss() only closes the current Modal. Meaning you will have to keep a reference to all open modals in and call dismiss() on each one.

    You can set use navController.setRoot(LoginPage) (link) to show the login-page.