[英]How to display data from an array filled with objects ionic angular
I am trying to display data from a weather api but i dont know how to do it because i cant show anything.我正在尝试显示来自天气 api 的数据,但我不知道该怎么做,因为我无法显示任何内容。 This is how i recieve the data when I do console.log(this.tiempo), as an array filled with objects
这就是我在执行 console.log(this.tiempo) 时接收数据的方式,作为一个充满对象的数组
But when i try to access to any object like this.tiempo.descripcion, it shows me an undefined.但是当我尝试访问像 this.tiempo.descripcion 这样的任何对象时,它会显示一个未定义的对象。 Why?
为什么?
This is my method to pass data between pages这是我在页面之间传递数据的方法
openDetails(){
let navigationExtras: NavigationExtras = {
state: {
previsiones: this.previsiones
}
}
this.router.navigate(['meteorologia'], navigationExtras);
}
And here I can treat it在这里我可以治疗它
tiempo: IMeteorologia;
constructor(private activeRoute: ActivatedRoute, private router: Router)
{
this.activeRoute.queryParams.subscribe(params => {
if (params && params.special) {
this.tiempo = JSON.parse(params.special);
}
if (this.router.getCurrentNavigation().extras.state) {
this.tiempo = this.router.getCurrentNavigation().extras.state.previsiones;
console.log(this.tiempo.descripcion) //Here is the undefined
}
});
}
This is my interface这是我的界面
export interface IMeteorologia {
descripcion: string;
diaSemana: Date;
tempMinima: string;
tempMaxima: string;
}
I hope I explained myself well.我希望我能很好地解释自己。
Fixed it.修复。 I was populating the array incorrectly
我错误地填充了数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.