Is there a way to close any open modals/alerts/dialogues?


I have session timers in my application which logs a user out automatically after a certain time limit.

I utilise various ionic generated alerts, modals etc in the application.

When a user is automatically logged out and they have been idle for some time, if there are dialogues which have not been closed by the user they remain on screen after the suer has been logged out.

Is there a way in ionic to close any open instances of dialogues? Or should I just use a pub/sub event to those controllers with dialogues to close them on logout?


Yeah i would use a custom event… thrown by a parent controller (around the other views) with e.g. $scope.$broadcast(‘userLoggedOut’).

The current open with hangs on that event and closes the modals/alerts … .

Anotherway would be to have a rootScope/Scope variable in the parent-controller and you set this variable to true or false. All child controllers have to set a watcher on that scope variable. But this approach is ugly… use the first one to avoid useless watchers.


I actually ended up doing it like this:

			if ($ionicPopup._popupStack.length > 0) {
				$ionicPopup._popupStack.forEach(function(popup, index) {
					if (popup.isShown === true) {
						return popup.hide();

After digging around in Ionic source I found that all popups are pushed to the _popupStack array. Even though it is denoted as private it can be accessed publicly and you can close any open popups from there.


Yeah but i like to keep in “modular” for each controller and so on.
But if this works for you it is okay.


This is not enough to close all the popups in the latest build of ionic 1.x. Here is a function that does it all (considering you have all the necessary services injected)

closeAllPopups = function () {
    noop = angular.noop;
    elevated = false;
    var popupStack = $ionicPopup._popupStack;
    if (popupStack.length > 0) {
      popupStack.forEach(function(popup, index) {
        if (popup.isShown === true) {

    //Remove popup-open & backdrop if this is last popup
    $timeout(function() {
      // wait to remove this due to a 300ms delay native
      // click which would trigging whatever was underneath this
      // $ionicPopup._popupStack.pop();
    }, 400, false);
    ($ionicPopup._backButtonActionDone || noop)();


$rootScope works for me