我正在尝试使用Angular 6中的HttpClient,但我遇到了一些问题。
我的代码如下所示:
TS
btc = this.http.get<any>(this.btcurl).subscribe(res => this.btc = res);
eth = this.http.get<any>(this.ethurl).subscribe(res => this.eth = res);
ltc = this.http.get<any>(this.ltcurl).subscribe(res => this.ltc = res);
progressInfoData = [
{
title: 'Bitcoin (BTC) Price',
value: this.btc,
activeProgress: 70,
description: 'Better than last week (70%)',
},
{
title: 'Ethereum (ETH) Price',
value: this.eth,
activeProgress: 30,
description: 'Better than last week (30%)',
},
{
title: 'Litecoin (LTC) Price',
value: this.ltc,
activeProgress: 55,
description: 'Better than last week (55%)',
},
];如您所见,我从一个url中获取信息,然后将此信息保存在一个数组中。问题是当我打印这个信息时,我没有得到json对象。
HTML
<nb-card size="medium">
<nb-card-body>
<div class="progress-info" *ngFor="let item of progressInfoData | async">
<div class="title">{{ item.title }}</div>
<div class="value">{{ item.value.EUR }}</div>
<nb-progress-bar [value]="item.activeProgress"></nb-progress-bar>
<div class="description">
<bdi>{{ item.description }}</bdi>
</div>
</div>
</nb-card-body>
</nb-card>但是,如果我将var直接放入html代码中:
<div class="value">{{ btc.EUR }}</div>它可以正确地打印信息。你知道为什么会这样吗?
提前感谢!
https://stackoverflow.com/questions/51976277
复制相似问题