Check out this snippet of code that I've been using for a different purpose, but thought it might be helpful:
import { Nav, Platform, IonicApp, ... } from 'ionic-angular';
@Component({
selector: 'page-custom',
templateUrl: 'custom.html'
})
export class CustomPage {
constructor(private platform: Platform,
private ionicApp: IonicApp) {
// ...
}
public displayNewModalByClosingCurrentOne(): void {
let activePortal = this.ionicApp._loadingPortal.getActive() ||
this.ionicApp._modalPortal.getActive() ||
this.ionicApp._toastPortal.getActive() ||
this.ionicApp._overlayPortal.getActive();
if (activePortal) {
// Dismiss the currently active portal
activePortal.dismiss();
activePortal.onDidDismiss(() => {
// Add logic to show the new modal here...
});
return;
}
}
// Alternatively, you can utilize the `activePortal` property to prevent
// displaying another loading screen before closing the current one.
public displayNewModal(): void {
let activePortal = this.ionicApp._loadingPortal.getActive() ||
this.ionicApp._modalPortal.getActive() ||
this.ionicApp._toastPortal.getActive() ||
this.ionicApp._overlayPortal.getActive();
if (!activePortal) {
// Show your new modal here
}
}
}