Ionic ionViewWillEnter not fire after becoming active from a NavController.pop()


let’s say we have a page A and a modal page B.

In page A we setup a lifecycle hook

 console.log("event onViewWillEnter fired");
 this.platform.registerBackButtonAction( () => {
  console.log("back button pressed!");

When we freshly enter into this page A the event is fired and the back button works as expected.
Let’s open up again page A, and from this page we show the model page B using the ModalController.present.
If we dismiss now page B (shown modal), the event onViewWillEnter is not being fired anymore while re-entering page A, but also the back button is not working anymore.

Accoring the ionic docs the event should be fired as page A becomes active again:

ionViewWillEnter void Runs when the page is about to enter and become the active page.

From my point of this sFrom my point of view this is a bug.
Or can someone explain this behaviour? What do you think?


ionViewWillEnter(), not onViewWillEnter()

1 Like

I believe the behavior is correct, even if it’s a little confusing at first. Page A is still the current page, even while Modal B is open, as Modal B isn’t a true page. It’s still declared a page, and is conceptually a page, but it isn’t a page in the same sense that Page A is a page. Instead, it’s a “page” that is overlayed across Page A.

I’m fairly certain this is the case, but there is of course always the possibility that I’m wrong.

@AaronSterling: yes, you’re absolutely right…

@SigmundFroyd: I could agree on that, but then the concept does not follow a red line. If so, the hw button should still be registered, even after coming back from a modal window…

It fires in my app when a modal dismisses. My guess is you just typed it wrong.

I just checked again., but the function is spelled right (it also works the first time i enter the page).

which version of ionic are u using?

Framework 3.5, but I don’t think that makes a difference. Maybe post code.

Here comes the code snippet:

 public ionViewWillEnter () {
    console.log("ionViewWillEnter fired");
    this.platform.registerBackButtonAction( () => {
      try {
        if (this.navCtrl.canGoBack) {
        } else {
      } catch (e) {
        console.log("unable to dismiss HW backbutton");

the console.log is not being executed after a modal return

Sorry, @SigmundFroyd is right and I’m wrong. I went back and looked, and ionViewWillEnter fires inside the modal when the modal enters. In the base page, when you present a modal, you don’t leave the base page, so ionViewWillLeave() doesn’t fire in the base page even though ionViewWillEnter() fires inside the modal. I had assumed that the one implied the other and it doesn’t.

Hey Aaron,

thanks for your reply! Does someone know en event, which is fired each time a page becomes the primary shown one?

1 Like

Hey, did someone figure this out? I am also looking for an event/method that fires each time a page becomes the primary shown one (like viewDidAppear in iOS for example). My problem is when the app is in the background and I click on a local notification which brings the app forward, but neither the ionViewDidLoad, ionViewWillEnter or ionViewDidEnter fire. Btw, I am using side-menu, if that makes a difference.

Is there any update on this issue? I was hoping it would be confirmed or fixed or maybe a workaround found for now.

1 Like

I need to call ionContent.resize when my login modal closes because the header/footer are dependent on user type. Unfortunately, since ionViewWillEnter, this isn’t working…

edit: since the data was changing on login, what I really needed to do was to use a ReplaySubject to listen for the loaded data and then trigger the ioncontent.resize method.

Present the same problem, the only request that occurred to me was:

let addModal = this.modalCtrl.create (‘newPage’);
addModal.present ();

this.navCtrl.push (‘newPage’);

And the ionViewWillEnter event will work normally.

If someone knows a better request please share.