# Force close any open ionic popup

**URL:** <https://forum.ionicframework.com/t/force-close-any-open-ionic-popup/33669>\
**Category:** ionic-v1\
**Created:** [October 1, 2015, 10:48pm UTC](https://forum.ionicframework.com/t/force-close-any-open-ionic-popup/33669 "2015-10-01T22:48:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pliablepixels](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pliablepixels/32/112372_2.png) [@pliablepixels](https://forum.ionicframework.com/u/pliablepixels)\
**Post date:** [October 1, 2015, 10:48pm UTC](https://forum.ionicframework.com/t/force-close-any-open-ionic-popup/33669/1 "2015-10-01T22:48:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sherlock](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sherlock](https://forum.ionicframework.com/u/sherlock)\
**Post date:** [October 14, 2015, 9:29am UTC](https://forum.ionicframework.com/t/force-close-any-open-ionic-popup/33669/2 "2015-10-14T09:29:23Z")

</div>

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 …
