I'm trying to work with angulafire2
to use my data stored in Firebase Database in my Angular app and I'm having some trouble with nested arrays.
I have an structure that looks like this:
items{
item1{
name: item1,
subitems{
subitem1{
name: subitem1
},
subitem2{
name: subitem2
}
}
}
}
I'm using a FirebaseListObservable
to get the items
array.
items: FirebaseListObservable<any>;
[...]
this.items = this.af.database.list('/items');
And the problem appears when I try to display the data.
<div *ngFor="let item of items | async">
<span>{{(item)?.name}}</span>
<div *ngFor="let subitem of (item)?.subitems">
<span>{{(subitem)?.name}}</span>
</div>
</div>
I get an error because item.subitems
is not recognized as an array.
Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
EDIT: I made a plunker that uses a test database in Firebase as the example above. HERE