Angular4 Error trying to diff '[object Object]'

≯℡__Kan透↙ 提交于 2019-12-01 11:37:35

If you want to have price as an array, then you have push the object in prices array.

ngOnInit(){
  this.surbtcService.getPricess()
  .subscribe(
    data => this.prices.push(data.ticker);
  );
}

OR, you can just directly access the object properties by assigning data.ticker to prices.

private prices = new SurbtcMarketView();

constructor(private surbtcService: SurbtcService) {

}
ngOnInit(){
   this.surbtcService.getPricess()
        .subscribe(data =>{
            this.prices = data.ticker;
        });
}

HTML:

<div *ngFor="let item of prices.min_ask">
  {{item}}
</div>

UPDATE:

See the Plnkr demo, I have resolved the issue that was causing error in parsing the json response.

Else you can also use this ,

prices : SurbtcService[] = [];

And then you can push the user object and make as a array,

this.prices.push(<<the data you want to push>>);
public getPricess() :Observable<SurbtcMarket> { return this.http.get('https://www.surbtc.com/api/v2/markets/btc-clp/ticker') .map((response: Response) => response.json() as SurbtcMarket); }

This might be due to the fact as it's not mapped to a type. And I assume this only retun one object otherwise you have to return an array.

public getPricess() :Observable<SurbtcMarket[]> { return this.http.get('https://www.surbtc.com/api/v2/markets/btc-clp/ticker') .map((response: Response) => response.json() as SurbtcMarket[]); }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!