NavController#ionViewDidEnter not firing when closing modal


#1

Hello,

When opening a modal from a component, how can I make sure a method on that component is called when the modal is closed? What I tried to do is listen to an re-entrance event but this only works when instead of modal I push a page.

I include my code below.

Thanks!

ionViewDidEnter() {
    if (AuthService.hasAccount() == false) {
      this.navCtrl.push(Signup);
      return;
    }
    this.authService.checkToken().subscribe(
      response => {
        this.loadData();
      },
      error => {
        console.log(error);
        // When opened as modal ionViewDidEnter is not re-called.
        this.modCtrl.create(AuthenticationPage, {}).present();
        // When opened as page we re-enter ionViewDidEnter when closing auth page.
        // this.navCtrl.push(AuthenticationPage);
        return;
      }
    );
  }

#2

Hmm, I dont think it’s an error with modal events, but your code. It looks like you’re trying to present a modal, then push a new view on the stack?

Either way, it’s not clear what you’re trying to do.
If you’re presenting a modal, then closing it, the view should not fire DidEnter, since the main Page Component is have not been changed, or navigated away from.


#3

Hello,

Thank you for your reply - ok, so it’s expected behaviour that ionViewDidEnter does not fire when closing a modal. Note, that part where I push a page is commented - it was just to illustrate that unlike with modals this way works.

All I want to do is open a modal from page A - and the moment it closes execute a piece of code in said page A.


#4

Could onDidDismiss be wrangled into doing what you want?


#5

Hello,

Yeah, guess I could pass back information using onDidDismiss or have an output on the modal component or affect some global object from within the modal but it’s less clean.

Basically, at the end of my ionViewDidEnter method - provided I haven’t returned from it due to user not having an account or not being logged in - I want to execute some stuff only applicable to logged users. I can carry out this action inside the modal - sure but I’d rather have it in one place.