由于很多我之前结合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