Answer the question
In order to leave comments, you need to log in
Angular 2 ngFor?
Hello, I can't figure out why it's throwing an error.
ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
//Выдает ошибка именно в этом варианте
{"in":{"231":{'name': 'test1'}, "2351":{'name': 'test2'}, "1231":{'name': 'test3'}}
//Тут все нормально
{"in":{"0":{'name': 'test1'}, "1":{'name': 'test2'}, "2":{'name': 'test3'}}
this.getJson().subscribe((data:any) => {
this.listers = data['in'];
}
<div *ngFor="let item of listers; let i=index"</div>
Answer the question
In order to leave comments, you need to log in
ngFor doesn't work with objects that can't be iterated. You need to cast data['in'] to an array. Try like this:this.listers = Object.values(data['in']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question