【发布时间】:2017-09-07 18:15:14
【问题描述】:
和我之前的很多人一样,我有这个错误:
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:无法读取未定义的属性“数据”
【问题讨论】:
-
请发布包含
*ngFor的html代码 -
如果
body.data没有items,它看起来与*ngFor无关。 -
你的 JSON 是什么样子的?
标签: angular rest-client