错误 Angular4 尝试 diff '[object Object]'

我正在尝试展示一些信息 dom, 但我收到这个错误:

错误:尝试时出错 diff '[object Object]'

我想做什么 - 它是通过这些数据
https://www.surbtc.com/api/v2/ ... icker
:

{"ticker":{"last_price": ["1771455.0","CLP"], "min_ask": ["1771432.0","CLP"], "max_bid": ["1660003.0","CLP"], "volume": ["178.37375119","BTC"], "price_variation_24h":"-0.107","price_variation_7d": "-0.115"}}

我想显示它 html, 像这样:


<div *ngfor="let price of prices">
{{price.min_ask}}
</div>


这是 service.ts:


import { Injectable } from '@angular/core';
import { Http, Headers, Response } from '@angular/http';
import 'rxjs/add/operator/toPromise';
import {Observable} from "rxjs";
import 'rxjs/Rx';
import 'rxjs/add/operator/catch';
import { SurbtcMarket } from './surbtcmarket'


@Injectable//
export class SurbtcService {

constructor/private http: Http, private surBtcMarket : SurbtcMarket/ { }

public getPricess// :Observable<surbtcmarket> {
return this.http.get/'https://www.surbtc.com/api/v2/markets/btc-clp/ticker'/
.map//response: Response/ =&gt; response.json///;
}

}


界面 surbtcmarket.ts


export class SurbtcMarket {
public ticker: SurbtcMarketView[];
}

export class SurbtcMarketView {
public last_price : number;
public min_ask : number;
public max_bid : number;
public volume : number;
public price_variation_24h : number;
public price_variation_7d : number;
}


component.ts


import { Http, Response, Headers } from '@angular/http';
import { SurbtcService } from '../../surbtc/surbtc.service';
import {Observable} from "rxjs";

@Component/{
selector: 'app-comprarltc',
templateUrl: './comprarltc.component.html',
styleUrls: ['./comprarltc.component.scss']
}/
export class ComprarltcComponent implements OnInit {

private prices = [];

constructor/private surbtcService: SurbtcService/ {
this.surbtcService = surbtcService;
}

ngOnInit//{
this.surbtcService.getPricess//
.subscribe/
data =&gt; this.prices = data.ticker
/;
}
}


</surbtcmarket>
已邀请:

风见雨下

赞同来自:

如果你想拥有
price

作为一个数组,那么你有
push

阵列中的对象
prices

.


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


OR, 您可以只需直接访问对象属性,分配
data.ticker


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:


https://plnkr.co/edit/malbXKcA ... eview
Plnkr, 我解决了解析回应时造成错误的问题 json.

知食

赞同来自:

否则你也可以使用它 ,


prices : SurbtcService[] = [];


然后您可以按下用户对象并制作数组,


this.prices.push/<<the data="" push="" to="" want="" you="">&gt;/;


</the>

快网

赞同来自:

public getPricess// :Observable<surbtcmarket> { return this.http.get/'https://www.surbtc.com/api/v2/markets/btc-clp/ticker'/ .map//response: Response/ =&gt; response.json// as SurbtcMarket/; }


这可能是由于它与类型的比较。 我认为这只是一个对象 retun, 否则,您必须返回数组。


public getPricess// :Observable<surbtcmarket[]> { return this.http.get/'https://www.surbtc.com/api/v2/markets/btc-clp/ticker'/ .map//response: Response/ =&gt; response.json// as SurbtcMarket[]/; }


</surbtcmarket[]></surbtcmarket>

要回复问题请先登录注册