如何在角度6 * ngfor中获取值对象的每个属性

时间:2019-04-17 20:38:44

标签: python angular6

我想从

之类的对象访问每个属性,例如“符号”,“公司名称”
{ "symbol": "AAME", "companyName": "Atlantic American Corporation", "previousClose_change": null, "change": -0.05, "changePercent": -0.02049, "latestTime": "April 17, 2019", "primaryExchange": "NASDAQ Global Market", "sector": "Financial Services", "marketCap": 48170048, "open": 2.46, "high": 2.47, "low": 2.39, "close": 2.39, "previousClose": 2.44, "latestVolume": 2569, "week52High": 3.8, "week52Low": 2.2 }

在我的代码data_service中,从python获取股票数据,我想显示该数据。

这是我的dataservice.ts

getCompany(marketcap:number): Observable<Company[]>
{
  return this.http.get<Company[]>('http://127.0.0.1:5000/employees/' + marketcap);
}

这是我的display.component.ts,在函数中具有以下代码:

company: Company[]=[];

passdetails() :  any {
    this.displayservice.getMovies(this.marketcap).subscribe(
          data=>
          {this.company=<Company[]>data ;
    });
}

这是我的display.component.html

<li *ngFor="let comp of company">
  {{comp.symbol}}
  {{comp.change}}
  {{comp.marketCap}}
</li>

<!--to display key values--->
<div *ngFor="let item of company | keyvalue">
  {{item.key}}:{{item.value}}
</div>

我希望输出为:

AAME //symbol
-0.05  //change
48170048 //marketCap
and key value pairs:

我得到的是:

0:{ "symbol": "AAME", "companyName": "Atlantic American Corporation", "previousClose_change": null, "change": -0.05, "changePercent": -0.02049, "latestTime": "April 17, 2019", "primaryExchange": "NASDAQ Global Market", "sector": "Financial Services", "marketCap": 48170048, "open": 2.46, "high": 2.47, "low": 2.39, "close": 2.39, "previousClose": 2.44, "latestVolume": 2569, "week52High": 3.8, "week52Low": 2.2 } 
1:{ "symbol": "AAMC", "companyName": "Altisource Asset Management Corp Com", "previousClose_change": null, "change": -0.32, "changePercent": -0.01067, "latestTime": "April 17, 2019", "primaryExchange": "NYSE American", "sector": "Financial Services", "marketCap": 47032946, "open": 29.6, "high": 30, "low": 29.388, "close": 29.68, "previousClose": 30, "latestVolume": 4570, "week52High": 73.4983, "week52Low": 22.6 } 
2:{ "symbol": "AAC", "companyName": "AAC Holdings Inc.", "previousClose_change": null, "change": 0, "changePercent": 0, "latestTime": "4:00:00 PM", "primaryExchange": "New York Stock Exchange", "sector": "Healthcare", "marketCap": 42808098, "open": 1.82, "high": 1.861, "low": 1.74, "close": 1.74, "previousClose": 1.74, "latestVolume": 132591, "week52High": 12.64, "week52Low": 1.33 } 

但是我没有得到符号和更改之类的属性的单个值。

0 个答案:

没有答案