【问题标题】:How to receive data from a modal?如何从模态接收数据?
【发布时间】:2023-04-06 23:54:02
【问题描述】:

我有一个带有选择过滤区域的模式。 当我打开模式时,我选择区域并显示该区域的数据,因此我想将该数据发送回第一页。而且我认为我做得对,因为在 CONSOLE 上我看到了过滤后的数据,但我不知道如何在第一页的 HTML 中显示。 谁能帮我这个?我不知道我到底需要做什么。

MODAL.TS

 export class FiltrosModalPage implements OnInit {
   public selectedFilter: string = 'regiao.id';
   regiao: any;
   regioes: Regiao[];
   myParam: string;
   produtos: Produto[];
   produtossubcategoria: Produtosubcategoria[];


   constructor(
     private viewController: ViewController,
     public navCtrl: NavController,
     public db: DatabaseProvider,
     public navParams: NavParams,
     public viewCtrl: ViewController
   ) {
     console.log(navParams.get('val'));
     this.regioes = navParams.get('val');
   }


   selecionaregiao(id) {
     this.db.getProdutosregiao(id)
       .then(data => this.produtos = data)
       .catch(error => console.log('Something want wrong!'));
       console.log('passou em tudo')
   }

   dismiss() {
     let data = this.produtos;
     this.viewCtrl.dismiss(data);
   }
}

HOME.TS

openFiltrosModal() {
  this.openModal('FiltrosModalPage');
}

openModal(pageName) {

  let filtrosModal = this.modalCtrl.create(pageName, {'val': this.regioes}, { cssClass: 'inset-modal' });
  filtrosModal.onDidDismiss(data => {
    console.log('MODAL DATA', data);
    this.value = data;
  });
  filtrosModal.present();
}

filter optioonsmy console

与控制台图像一样,我在第一页 html 上获取此数据。但我不知道如何显示。

【问题讨论】:

    标签: angular cordova ionic-framework


    【解决方案1】:

    由于您将数据保存在类的属性 (this.value) 中,您只需要一个 ngFor to iterate through the arrays 并显示数据。

    你可以在你的 HTML 上这样做

    <!-- Here you'll use the ngIf to just show the list itens if there's something on value -->
    <ion-list *ngIf="value">
      <!-- ngFor'll iterate your array and render a new element for every item in your array -->
      <ion-item *ngFor="let item of value">
        <!-- then you can access an property of your object in that array position -->
        {{item.nom_regiao}}
      </ion-item>
    </ion-list>
    

    确保value 在模态过滤之前没有任何值,如果它被初始化为任何值,则必须更改ngIf 条件。

    希望这会有所帮助。

    【讨论】:

    • 我收到几行内容,但没有文字或任何内容。但根据模态,项目的数量是正确的。但是为什么没有内容呢?
    • 属性名是否正确?试试{{item.id}},有没有显示内容?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-13
    相关资源
    最近更新 更多