Close the alert/modal from different page


#1

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.


#2

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


#3

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.


#4

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.


#5

Mohd-PH has the correct answer


#6

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.


#7

Thanks Mohd-PH, let me try it out


#8

You are welcome :blush: