0
Good afternoon to everyone, I am consuming an api, but I can not display it in my template, it is consumed, appears on the console, but I can not 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>
Error appears :
Cannot find a differ supporting Object '[Object Object]' of type 'Object'. Ngfor only Supports Binding to Iterables such as Arrays.
Along those lines
Data : {{c.date}} Valor Compra {{c.buy}} Valor Venda {{c.sell}}
you are saying that in your array there is an object with the buy, sell and date properties. As is the response ofconsole.log(this.cotacao);
? Maybe just change your quote array tocotacao: string [{ }]}}
;– Marconi
This friend : {"Ticker": {"high": "29399.00000000", "low": "28234.00000000", "vol": "126.05166124", "last": "29000.12224000", "buy": "29000.13024000", "sell": "29282.98250000", "date": 1535741070}}
– Marcos Fernandes
Have you noticed that this is a javascript object and not an array?
– Marconi
You are using Typescript or Javascript?
– Marconi
I noticed yes. I am using Typescript
– Marcos Fernandes
You iterate with
ngFor
over an array– Marconi