简体   繁体   中英

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. This is how i recieve the data when I do console.log(this.tiempo), as an array filled with objects

But when i try to access to any object like this.tiempo.descripcion, it shows me an undefined. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM