如何获取角度为6*ng的值对象的每个属性

2024-09-27 19:22:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从对象中访问每个属性,如“symbol”、“companyname”

{ "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 } 

但我没有得到像符号和变化这样的属性的单独值


Tags: closeopensymbolchangenulllowhighsector

热门问题