Bittrex API返回“结果” [对象对象]

时间:2018-07-02 02:13:19

标签: api angular6

使用Angular 6我无法弄清楚如何从Bittrex API请求https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-ltc中显示“结果”数组

我可以获取API,没问题并显示对象,但是结果数组像[object Object]一样出现

成功true
留言
结果[object Object]

这是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>

console log

1 个答案:

答案 0 :(得分:0)

正如您在JSON中看到的那样,该对象包含一个名为git commit --amend的属性,该属性是包含价格的数组。

因此,您必须使用此属性,如下所示:

result