错误 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, 像这样:
这是 service.ts:
界面 surbtcmarket.ts
component.ts
</surbtcmarket>
错误:尝试时出错 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/ => 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 => this.prices = data.ticker
/;
}
}
</surbtcmarket>
没有找到相关结果
已邀请:
3 个回复
风见雨下
赞同来自:
作为一个数组,那么你有
阵列中的对象
.
OR, 您可以只需直接访问对象属性,分配
.
HTML:
UPDATE:
看
https://plnkr.co/edit/malbXKcA ... eview
Plnkr, 我解决了解析回应时造成错误的问题 json.
知食
赞同来自:
然后您可以按下用户对象并制作数组,
</the>
快网
赞同来自:
这可能是由于它与类型的比较。 我认为这只是一个对象 retun, 否则,您必须返回数组。
</surbtcmarket[]></surbtcmarket>