如何侦听模态关闭事件?
问题描述:
我需要知道我的模态已关闭。似乎没有一个明确的方式来做到这一点与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.
}
答
你只需要听模式关闭事件在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();
}
`
答
你会只是做
// 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找到。