【发布时间】:2018-11-25 00:20:43
【问题描述】:
我正在尝试使用新的 Public API V2 CoinMarketCap,但我在这方面遇到了一些困难。
JSON:
https://api.coinmarketcap.com/v2/ticker/?limit=10
我的模型币:
export class Coins {
id: string;
name: string;
symbol: string;
rank: number;
price_usd: number;
price_btc: number;
_24h_volume_usd: number;
market_cap_usd: number;
available_supply: number;
total_supply: number;
percent_change_1h: number;
percent_change_24h: number;
percent_change_7d: number;
last_updated: number;
}
我的服务:
urlBase = 'https://api.coinmarketcap.com/v2/ticker/?limit=10';
getCoins() {
return Observable
.timer(0, 5000)
.flatMap(() => this.http.get(this.urlBase))
.pipe(
map(res => res),
catchError(this.handleError)
)
}
我的组件:
coins: Coins[];
getCoins() {
this.coinsService.getCoins().subscribe(
data => {
this.coins = data;
});
}
我的html:
<div class="card card-inverse" *ngFor="let coin of coins">
输出:
ERROR Error: Cannot find a differ supporting object '[object Object]' of type
'object'. NgFor only supports binding to Iterables such as Arrays.
有什么建议吗?
谢谢
【问题讨论】:
-
你能告诉我
Coin的定义吗 -
尝试使用 *ngFor="let coin in coin"。
标签: javascript json angular api