2017-05-30 69 views
3

我需要知道我的模態已關閉。似乎沒有一個明確的方式來做到這一點與ionViewDidLeave或類似的東西。我嘗試了ionViewDidLeave,並且感覺它不適用於模式關閉,因爲我沒有使用navController移動到該頁面,而是使用模式顯示頁面。如何偵聽模態關閉事件?

home.ts

/*show modal with post form on add event page */ 

    postEvent(){ 

     let modal = this.modalCtrl.create(AddEvent); 
     modal.present(); 


} 

AddEvent.TS

/* Close modal and go back to feed */ 

    close(){ 

    this.viewCtrl.dismiss(); 

     //I need to change a value on the home page when this dismiss happens. 

    } 

回答

4

你只需要聽模式關閉事件在home.ts

// listen for close event after opening the modal 
    postEvent(){ 
     let modal = this.modalCtrl.create(AddEvent); 
     modal.onDidDismiss(() => { 
     // Call the method to do whatever in your home.ts 
      console.log('Modal closed'); 
    }); 
    modal.present(); 
} 

`

1

你會只是做

// home.ts 
// ------- 

postEvent() { 

    let modal = this.modalCtrl.create(AddEvent); 

    modal.onDidDismiss(data => { 
    // Do stuff with the data you closed the modal out with 
    // or do whatever else you need to. 
    }); 

    modal.present(); 

} 

您可以在docs找到。