首页 > 解决方案 > 无法处理通过 Ionic 4 中 modal.onDidDismiss() 捕获的数据

问题描述

在使用 modal.onDidDismiss()方法将其关闭后,我成功地从模态页面捕获数据(对象),但我无法处理和显示它:

export class AbracadabrasyPage {

  private fastFood: any; 

  Menus: any[]; 
  Horaires: any[]; 
  Category: string; 


  constructor(public modalController: ModalController, private routerOutlet: IonRouterOutlet)
  { 
    console.log(this.fastFood); // it displays in the console : Undefined //

    this.Menus = this.fastFood.menus; 
    this.Horaires = this.fastFood.horaires; 
    this.Category = this.fastFood.cat
  };


  async onLOcate(){     
    const modal = await this.modalController.create({
      component: MapPage,
      swipeToClose: true,
      componentProps: {
        Lat: this.fastFood.latitude, 
        Lng: this.fastFood.longitude
      },
      presentingElement: this.routerOutlet.nativeEl 
    });
    modal.present(); 

    const { data } = await modal.onDidDismiss(); 
    if(data){
      this.fastFood = data;
      console.log(this.fastFood);
    };
  };

标签: javascriptangulartypescriptionic4modalviewcontroller

解决方案


推荐阅读