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?
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.
This worked for me
constructor(public navCtrl: NavController,public ionicApp: IonicApp){}
this.viewCtrl.dismiss().then(_=>{
let activePortal = this.ionicApp._modalPortal.getActive()
if (activePortal) {
activePortal.dismiss(); //can use another .then here
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With