>我有一个用离子 4 和角度 7 开发的旧应用程序,有一个组件呈现模态 A,然后,模态 A 呈现模态 B,当模态 B 被关闭时,将数据传递给模态 A 关闭并将数据传递给组件,现在我想切换到角度 8,新应用程序可以呈现模态 A 和模态 B,但是当模态 B 关闭时, 模态-A 不会关闭,这就是组件呈现模态 A 的方式:
const modal = await this.modalCtrl.create({
component: SelectorItemsPage,
componentProps: {
item: this.item,
title: this.text,
service: this.service,
filterFunction: this.filterFunction,
sorterFunction: this.sorterFunction,
createPopup: this.createPopup
}
});
modal.onDidDismiss().then(data => {
this.item = data.data
this.selectedItem.emit(data.data)
this.writeValue(this.item)
modal.dismiss(this.item)
})
return await modal.present()
这就是模态-A 呈现模态 B 的方式:
const modal = await this.modalCtrl.create({ component: this.createPopup })
modal.onDidDismiss().then(item => {
this.modalCtrl.dismiss(item.data)
})
return await modal.present()
提前致谢
为每个模态设置一个id:
const modal = await this.modalCtrl.create({
component: SelectorItemsPage,
componentProps: {
item: this.item,
title: this.text,
service: this.service,
filterFunction: this.filterFunction,
sorterFunction: this.sorterFunction,
createPopup: this.createPopup
},
id: 'SelectorItems'
});
和
const modal = await this.modalCtrl.create({
component: this.createPopup,
id: 'Popup'
})
因此,当您关闭时,将id作为参数传递:
modal.dismiss(this.item, '', 'SelectorItems')
和
this.modalCtrl.dismiss(item.data, '', 'Popup')
更多信息: [1] https://github.com/ionic-team/ionic/issues/20369 [2] https://github.com/mluis/ionic4-modal-modal-issue/pull/1/files<所有学分>所有学分>