1

我有一个用 ionic 4 和 angular 7 开发的旧应用程序,有一个组件显示模态-A,然后模态-A 呈现模态-B,当模态-B 被解除时,将数据传递给模态-A,后者解除并传递数据到组件,现在我想切换到angular 8,新app可以呈现modal-A和modal-B,但是当modal-B关闭时,modal-A不关闭,组件是这样呈现modal-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()

这就是modal-A呈现modal-B的方式:


    const modal = await this.modalCtrl.create({ component: this.createPopup })

    modal.onDidDismiss().then(item => {

      this.modalCtrl.dismiss(item.data)
    })

    return await modal.present()

提前致谢

4

1 回答 1

3

为每个模态设置一个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 <所有学分

于 2020-04-03T20:36:15.693 回答