我不知道如何显示Bittrex请求https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-ltc中的“结果”数组
我可以获得API,没有问题,并显示对象,但是结果数组像对象对象一样出现。
成功真实
消息
结果对象对象
以下是HTML代码:
<tr *ngFor="let price of objectKeys(prices)">
<td>{{ price }}</td>
<td>{{ prices[price] }}</td>
</tr>
我只想知道正确的HTML代码来显示结果数组中的任何参数。任何帮助都将不胜感激。
谢谢
编辑:添加完整代码
data.service:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class DataService {
result: any;
constructor(private http: HttpClient) { }
getPrice() {
return this.http.get('https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-ltc')
}
}
component.ts:
import { Component } from '@angular/core';
import { DataService } from './data.service';
import { Observable } from 'rxjs';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
objectKeys = Object.keys;
prices: any;
constructor(private data: DataService) {
}
ngOnInit() {
this.data.getPrice()
.subscribe(res => {
this.prices = res;
});
}
}
component.html
<h2>Bittrex Results</h2>
<div *ngIf="prices">
<table id="pricetable">
<tr>
<th>Bittrex Close</th>
<th>Bittrex Volume</th>
<th>Test</th>
</tr>
<tr *ngFor="let price of objectKeys(prices)">
<td>{{ price }}</td>
<td>{{ prices[price] }}</td>
<td>{{ prices[price] }}</td>
</tr>
</table>
</div>
发布于 2018-07-02 06:56:57
正如您在获得的JSON中所看到的,该对象包含一个名为result
的属性,该属性是包含价格的数组。
所以你必须使用这个属性,像这样:
this.data.getPrice()
.subscribe(res => {
this.prices = res.result;
});
https://stackoverflow.com/questions/51128381
复制相似问题