Display api with Ionic

0

Good afternoon everyone, I'm consuming an api, but I can not display it in my template, it's being consumed, it appears on the console, but I can not get it in the template.

Component:

import { PaisesProvider } from './../../providers/paises/paises';
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  cotacao: string [];
  constructor(public navCtrl: NavController,
              private paisesProvider: PaisesProvider) {


  }

  ionViewDidLoad() {
    this.listaCotacao();  

  }

  listaCotacao() {
    this.paisesProvider.listaPaises()
    .subscribe(data => {
      this.cotacao = data;
      console.log(this.cotacao);

    });
  }
}

Template: 

<ion-header>
  <ion-navbar>
    <ion-title>Home</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>

    <ion-item  *ngFor="let c of cotacao">
      Data : {{c.date}} Valor Compra {{c.buy}} Valor Venda {{c.sell}}    
    </ion-item>          

</ion-content>

The error appears:

  

Can not find a supporting object '[object Object]' of type   'object'. NgFor only supports binding to Iterables such as Arrays.

    
asked by anonymous 31.08.2018 / 19:52

1 answer

0

You're giving *ngFor to some response that is not an array, that's what he's complaining about, it's coming as an object. If you want to display the fields of this object.

In case of this response that you have informed, it is an object, so you do not have to go through the values of it, just access them directly, for example: c.date c.buy , and so on.

    
31.08.2018 / 20:01