Ionic 3如何从一页到另一页接收数 组

问题描述 投票:0回答:1

我需要将数组从一页传递到另一页。在第一页中,通过从列表中选择项目来创建数组,然后将所有项目推入正常状态,但是当我在另一页中收到此数组时,它成为数组对象,并且无法读取html页中的数据,这是我的代码的一部分:

labo.ts-这是我创建数组的方式,这很好

selectItem(itemKey){
   const foundAt = this.selectedQuestions.indexOf(itemKey);
   if (foundAt >= 0) {
      this.selectedQuestions.splice(foundAt, 1);
   } else {
      this.selectedQuestions.push(itemKey);
   }
  console.log(this.selectedQuestions);

}

添加完项目后,将其发送到calendar.ts

calendar(){
 console.log("ARRAY ", this.selectedQuestions)
    this.navCtrl.push(CalendarioPage,{
      queryParams: {
           value : this.selectedQuestions
       },
  });

}

这是calendaar.ts,我需要在其中接收数组:

 export class CalendarioPage {
  datos: Array<object>;

  constructor(public navCtrl: NavController, public navParams: NavParams,
    public http: Http, private conteSearch : ContesearchProvider) {

    this.datos = navParams.get("queryParams");

    console.log("array -> ", this.datos)

  }  
 }

在我的calendar.html文件中,我尝试读取数组:

<div *ngFor="let dato of datos">
  {{dato.nombre}} 
</div>

并且我收到此错误“ ERROR错误:”未捕获(承诺):错误:找不到类型为'object'的其他支持对象'[object Object]'。 NgFor仅支持绑定到Iterables,例如数组。“

这是数组前后的外观(当在calendar.ts中收到时)

enter image description here

预先感谢您提出任何建议!

typescript ionic3 angular4-router
1个回答
0
投票

您传递的数组在对象this.datos的值键处可用

所以您需要像this.datos.value一样阅读它,它应该可以工作。

感谢

© www.soinside.com 2019 - 2024. All rights reserved.