由於很多我之前結合Iterables,我有這樣的錯誤:再度NgFor僅支持如數組
Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
我嘗試了許多解決方案,如: error display in *ngfor json array object
但沒有任何工程。
public getInterfaces(): Observable<InterfaceBrief[]> {
let headers = this.createBasicHeaders();
let options = new RequestOptions({
method: 'get',
headers: headers});
let url = this.restApi +"/dashboard/list";
console.log(url);
return this.http.get(url, options)
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
let body = res.json();
console.log("GOOD");
return body.data || {};
}
export class DashboardComponent implements OnInit {
errorMessage: string;
interfacesBrief: InterfaceBrief[];
constructor(private _service: AuthService, private _emotService: EmotClientService) {
}
ngOnInit() {
this.getInterfaces();
}
getInterfaces() {
this._emotService.getInterfaces().subscribe(
data => this.interfacesBrief = data,
error => this.errorMessage = <any>error
);
}
}
當我改變了:
return body.data || {};
到:
return body.data.items || {};
我有錯誤:
Cannot read property 'items' of undefined
ERR:無法讀取的不確定
請張貼含有'你的HTML代碼* ngFor' –
如果'body.data'沒有'items',它看起來與'* ngFor'沒有關係。 –
你的JSON是怎樣的? – Alex