pedrum golriz
pedrum golriz

Reputation: 512

Listen to modal dismiss in ionViewCanLeave

I'm trying to present a modal during route change for a form, but getting stuck with how to return the result to ionViewCanLeave.

ionViewCanLeave(): boolean {
    debugger;
    let modal = this.modalCtrl.create(this.cancelModal);
    let returnStatement = null;
    modal.onDidDismiss(data => {
      debugger;
      returnStatement = data;
    });
    modal.present();
    if(returnStatement !== null ){
      return returnStatement;
    }
  }

How would I wait for onDidDismiss to trigger before calling the return statement for ionViewCanLeave?

Upvotes: 1

Views: 223

Answers (1)

Hyuck Kang
Hyuck Kang

Reputation: 1789

I think you'd better change your pattern to do what you want.

As fas as I know there is no way to stop ionViewCanLeave() returning.

Thus, make another function which asynchronously executes leave page function after modal onDidDismiss like the below.

checkCanLeave(){
  debugger;
  let modal = this.modalCtrl.create(this.cancelModal);
  modal.onDidDismiss(data => {
    debugger;
    // Put on your leave page function like 'this.navCtrl.pop()' orr 'this.viewCtrl.dismiss'
  });
  modal.present();
}

Upvotes: 1

Related Questions