【发布时间】:2018-12-22 15:11:29
【问题描述】:
在控制台中收到此错误:
找不到不同类型的支持对象“[object Object]” '目的'。 NgFor 只支持绑定到 Arrays 等 Iterables。
services.ts
private url = "https://api.iextrading.com/1.0/stock/market/batch?symbols=SNAP,fb,AIG%2b,GOOG,AAPL,AMZN&types=quote";
constructor(private http: HttpClient) {}
getCID(): Observable<any> {
return this.http.get<any>(this.url);
}
组件.ts
ngOnInit() {
this.svc.getCID().subscribe(data => {
this.cidData = data;
console.log(data);
});
component.html
<div *ngIf="cidData">
<ul>
<li *ngFor="let x of cidData">
<a routerLink="/companydetails/{{x.symbol}}">{{x.symbol}}</a>
API 调用提供
{"GOOG":{"quote":{"symbol":"GOOG","companyName":"Alphabet Inc."}}, "SNAP":{etc...}
我认为问题在于 cidData 不是数组,但我不确定如何将其作为数组返回
【问题讨论】:
标签: javascript angular api