需求:当你已经打开了一个模态窗A的时候,想在这个模态窗A的基础上再打开一个模态窗B。
**原理:**要在A的上下文环境下创建B
如下图直接创建是会报错的(this.modalController.create is not a functoin)

要在构造方法constructor里改变presentModal方法的this指向,指向modalController;使其在同一个上下文。
constructor(public modalController: ModalController) {
this.presentModal = this.presentModal.bind(this.modalController)
}
此时resentModel方法的this已经指向modalController;
async presentModal() {
let that = this;
const modal = await that.create({
component: ModalPage
});
return await modal.present();
}
本文介绍如何实现在已打开模态窗A的基础上再次打开模态窗B的技术细节。通过调整构造方法中的presentModal方法指向,确保B能在A的同一上下文中正确加载。
2387

被折叠的 条评论
为什么被折叠?



