Force close any open ionic popup


#1

Hi is there any way to force close any open ionic popup? I know I can assign a variable to it and call close on that variable, but I wonder if there is a way to close any open popup without having to track it?

The specific use case is that I am trying to handle the case when the app goes to background and resumes. In this case, any open popup remains open and when I resume I switch screens to ask the user for a PIN and then go back to the old screen – but the popup keeps floating on top during this transition. Different views have multiple popups and some views have more than one - so tracking which one may be open and closing only that one is not convenient.

The solution I have now is I’ve defined $rootScope.zmPopup which all my popups use and in app.js I have a “onPause” that does if ($rootScope.zmPopup) $rootScope.zmPopup.close() which works but uses rootScope

Thanks


#2

I use a custom event to close all modals / popups if necessary. Just add

$scope.$on(EVENTS.hideAllModals, function() {
     myPopup.close();
});

after any popup definition. Then fire the event when popup should be closed.

BUT: In current version of ionic the popup stack gets destroyed when more than one popup is open …