As many before me, I have this error :
Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
I was trying many solutions like : error display in *ngfor json array object
But nothing works.
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
);
}
}
When I changed:
return body.data || {};
to :
return body.data.items || {};
I have error :
Cannot read property 'items' of undefined
ERR :Cannot read property 'data' of undefined