从 ModalController.create() 向组件传递数据

Passing data to a component from ModalController.create()

有没有一种方法可以传递这个 itemId 参数,以便 MarketPlaceItemPage 可以使用该数据?

async presentMarketplaceItem(itemId: number) {
    const modal = await this.modalController.create({
      component: MarketplaceItemPage,
      cssClass: '',
      mode: 'ios',
    });
    return await modal.present();
  }

我只是没有在 Ionic 文档中找到我需要的内容。 提前致谢!

我从这个网站找到了一些有用的东西 https://www.freakyjolly.com/ionic-modal-popovers-pass-receive-data/

async presentMarketplaceItem(itemId: number) {
    const modal = await this.modalController.create({
      component: MarketplaceItemPage,
      componentProps:{
        id: itemId
      },
      cssClass: '',
      mode: 'ios',
    });
    return await modal.present();
  }

Here is the official documentation from Ionic

您要找的属性是componentProps。 Ionic 控制器未在其 v5 文档中列出,但在 v4 下列出。

另一种方法(IMO 更快)是直接浏览源代码(ctrl+单击),它会显示控制器方法签名。