Typescript Ionic 3如何从一页到另一页接收阵列
我需要将数组从一页传递到另一页。在第一个页面中,数组是通过从列表中选择项目创建的,它推送所有项目ok,但当我在另一个页面中收到此数组时,它变成了一个数组对象,我无法读取html页面中的数据,以下是我代码的一部分: 这是我创建数组的方法,它很好Typescript Ionic 3如何从一页到另一页接收阵列,typescript,ionic3,angular4-router,Typescript,Ionic3,Angular4 Router,我需要将数组从一页传递到另一页。在第一个页面中,数组是通过从列表中选择项目创建的,它推送所有项目ok,但当我在另一个页面中收到此数组时,它变成了一个数组对象,我无法读取html页面中的数据,以下是我代码的一部分: 这是我创建数组的方法,它很好 selectItem(itemKey){ const foundAt = this.selectedQuestions.indexOf(itemKey); if (foundAt >= 0) { this.selectedQu
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
},
});
}
这是calendar.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)
}
}
导出类日历页{
datos:数组;
构造函数(公共navCtrl:NavController,公共navParams:navParams,
公共http:http,私有conteSearch:ContesearchProvider){
this.datos=navParams.get(“queryParams”);
log(“array->”,this.datos)
}
}
在我的calendar.html文件中,我尝试读取数组:
<div *ngFor="let dato of datos">
{{dato.nombre}}
</div>
{{dato.nombre}}
我收到了这个错误“error error:”Uncaught(在promise中):error:找不到类型为“object”的不同支持对象“[object object]”。NgFor仅支持绑定到阵列之类的Iterables。”
这是阵列前后的外观(在calendar.ts中接收时)
提前感谢您的任何想法!您传递的数组在对象this.datos的值键处可用 所以你需要像这样读它。datos.value,应该可以
谢谢Hi-Tek,它很有效,非常感谢。我只是更改了html:{{dato.nombre}