I am building an Ionic 2 app using ngrx, but I have a problem in dismissing overlay components.
To login I show the user a modal with a login-form. This dispatches an action which is handled not in the page but somewhere else. If the login was successful I want to set a new root-page and dismiss all overlay components (in this case the modal). This cannot be done from within the modal component since all the logic is handled somewhere else.
I already tried: clearing the whole navigation stack, calling popToRoot() and some other things but nothing worked. The is not dismissed.
Is there a way to dismiss all the modals/page except the root-page? I would want to have something like this:
Create a service that you inject in all of the classes that use the modals. Use the service to display modals and push into an array. Use the service to iterate through the array to dismiss all modals that were created.
The big benefit of using event for closing modals is that you can publish the event from anywhere, any class, any context, and the subscribed modal will catch it.
For the sake of completeness, the exact code I used for subscribing to the event is:
Ok so I had the same issue and I solved it this way. The solution is to store all the modal instances using a service in an array. Then use a loop and dismiss all the modals refering them from that array.
modal.html
<ion-button (click)="openModal()"> Open Modal <ion-button>
<ion-button (click)="close()"> Close Modals <ion-button>