Reputation: 3076
I'm trying to display a list of objects in my Firebase Database, but I am having a hard time to add the objects to the FirebaseListObservable.
Here is my code:
products: FirebaseListObservable<any[]>;
this.db.list('products/' + this.user.uid, { preserveSnapshot: true})
.subscribe(snapshots=>{
var jsonObject = [];
snapshots.forEach(snapshot => {
jsonObject.push(snapshot.val());
});
this.products = jsonObject;
});
The error I get is that I can't assigne any[] to a FirebaseListObservable.
This is my HTML:
<ion-list>
<ion-item class="text" *ngFor="let product of products | async">
{{product}}
</ion-item>
</ion-list>
My database looks like this:
Upvotes: 0
Views: 637
Reputation: 70
your products is FirebaseListObservable, however, your jsonObject is an array, so you can't let this.products = jsonObject
maybe you should do like the following:
products: Observable<any[]>;
this.products = this.db.list('products/' + this.user.uid, { preserveSnapshot: true})
.map(snapshots=>{
return snapshots.map(snapshot => {
return snapshot.val();
});
});
Upvotes: 3