模态窗体关闭时的回调
问题描述:
如何在离子模式2(v 2.1.7
)中关闭模态窗体后调用方法?以下是我的工作流程模态窗体关闭时的回调
- 用户加载一个页面(A)
- 然后点击一个按钮,打开一个模式窗体(页B)
- 添加一些细节(这将更新服务)
- 关闭模式窗体(页B)
- 现在我想一个回调添加到页面A,从 读取新的价值服务
这是世界卫生大会T I做过
#page A
let modal = this.modalCtrl.create(NewListPage);
modal.present();
getValueFromService()
#page B
updateService()
this.viewCtrl.dismiss();
目前发生的事情是,一旦程序碰到modal.present();
,它不是等待Page B
它去getValueFromService()
之前关闭,由于这一点,最近更新的价值不能被读取一次我关闭模式形式。
任何帮助,将不胜感激
欢呼
答
您可以使用onDidDismiss
(doc)是这样的:
// Page A
presentModal() {
let modal = this.modalCtrl.create(NewListPage);
modal.onDidDismiss(() => {
// This is going to be executed when the modal is closed, so
// you can read the value from the service here
getValueFromService();
});
modal.present();
}
然后像你说的
// Page B
updateService();
this.viewCtrl.dismiss();
也请注意你可以在之间发送数据和Page B
,所以也许你甚至可以避免使用服务(如果你这样做只是为了发送数据来回),只是发送数据是这样的:
// Page A
presentModal() {
let modal = this.modalCtrl.create(NewListPage);
modal.onDidDismiss(dataFromModal => {
// You can use the data here
console.log(dataFromModal.foo);
});
modal.present();
}
而在网页B
// Page B
// Instead of calling the service, you can send the data to the caller
let data = { 'foo': 'bar' };
this.viewCtrl.dismiss(data);
谢谢队友,完美的作品 – sameera207
很高兴听到:) – sebaferreras