gpt4 book ai didi

ionic-framework - Ionic 在 Modal 出现后全局调用函数

转载 作者:行者123 更新时间:2023-12-05 07:37:41 25 4
gpt4 key购买 nike

我想在每次出现模式后弹出一个警告框。

我知道我可以做这样的事情 modal.present().then(()=>alert("Modal presented"))

但是,我有30多个页面,里面有modalController。将 promise 调用添加到每个页面是低效的。

有什么方法可以在呈现模式框后全局自定义事件,这样我就不需要更新所有页面了吗?

最佳答案

您应该创建一个函数来在您的服务 中显示模态。每个你想显示模态的,使用那个函数。因此,您可以处理每个模式演示的成功回调。

yourProvider.ts

showModal(component, data) {
this.modalCtrl.create(component, data).present().then(() => {
console.log("show modal success");
//Add your alert here
alert("Modal presented");
}).catch(error => {
console.log("show modal error", error);
});
}

每当显示模态时调用上面的函数:

yourPage.ts

this.yourProvider.showModal("SomePage");

请注意:这只是一个建议。我没有在实际项目中使用这种方式展示不能指出它的任何缺点。

关于ionic-framework - Ionic 在 Modal 出现后全局调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48415369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com