Comme beaucoup d'autres avant moi, j'ai cette erreur:Une fois NgFor ne supporte que la liaison à Iterables tels que des tableaux
Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
je tentais de nombreuses solutions comme: error display in *ngfor json array object
Mais rien ne fonctionne.
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
);
}
}
Quand je changé:
return body.data || {};
à:
return body.data.items || {};
J'ai erreur:
Cannot read property 'items' of undefined
ERR: Impossible de lire la propriété 'données' undefined
s'il vous plaît postez votre code html contenant '* ngFor' –
Il ne semble pas lié à '* ngFor' si' body.data' n'a pas 'items'. –
À quoi ressemble votre JSON? – Alex