Close the alert/modal from different page

I have 2 pages, home page and login page. In home page there is button when you press the button, it will popup and alert. Also in home page there is timer running it will logout (setroot to login page) you after certain time period.

Assume that user clicked on the button and popup appeared and waited for time interval to automatically navigate back to login page.

In this situation, i would like close the alert which i open on home page from login page.

I would appreciate all your help and suggestions. Thanks.

Wouldn’t it be easier to close it on the home page when you navigate back to the login page?

Yes you are right, i can close alert on ionicViewWillLeave(). In real project i have many pages and all alertController handles are private. I am thinking how do i close without reference to alertcontroller handles. i would be happy If something like ViewController dismiss can work.

An idea but I didn’t try it, Create a service for the alert and add two methods one to present and the other to dismiss the alert, then inject the service to the constructor of the home and login pages.

1 Like

Mohd-PH has the correct answer

Indeed @Mohd-PH has the right idea. In my apps I use a service for the LoadingController component, which I then call from each of my components that want to display a loader.

If implemented as a service this also allows for other useful capabiblities, such as notifying a server anytime a loading controller times out.

Thanks Mohd-PH, let me try it out

You are welcome :blush: