[英]How to display data from an array filled with objects ionic angular
我正在嘗試顯示來自天氣 api 的數據,但我不知道該怎么做,因為我無法顯示任何內容。 這就是我在執行 console.log(this.tiempo) 時接收數據的方式,作為一個充滿對象的數組
但是當我嘗試訪問像 this.tiempo.descripcion 這樣的任何對象時,它會顯示一個未定義的對象。 為什么?
這是我在頁面之間傳遞數據的方法
openDetails(){
let navigationExtras: NavigationExtras = {
state: {
previsiones: this.previsiones
}
}
this.router.navigate(['meteorologia'], navigationExtras);
}
在這里我可以治療它
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
}
});
}
這是我的界面
export interface IMeteorologia {
descripcion: string;
diaSemana: Date;
tempMinima: string;
tempMaxima: string;
}
我希望我能很好地解釋自己。
修復。 我錯誤地填充了數組
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.