I have now this piece of code to filter an observable.
listings$: Observable<Listing[]>;
this.listings$ = this.firestore
.getListings()
.pipe(map(listings => listings.filter(listing => listing.promoted === true)));
Which works fine, but I want to make full use of rxjs instead of using the filter on the array.
The this.firestore.getListings() function returns Observable<Listing[]>, and this.listings$ must be Observable<Listing[]> as well.
I tried different approaches, and struggling with this for a while. Maybe you can help me. I'm still "fresh" to angular and rxjs.
this.listings$ = this.firestore.getListings().pipe(
mergeMap(listings => listings),
filter(listing => listing.promoted === true)
);
Type
Observable<Listing>is not assignable to typeObservable<Listing[]>.
I might be doing something wrong with the mergeMap operator, or even it is not correct operator to use in this case.
I tried to adjust the code from this post. The flatMap operator seem to be changed to mergeMap. But it's still not working.
this.listings$. Outside of the code shown, you must adjust the code to match an observable stream of individual listing objects. I guess that form is more convenient for your view?listings$: Observable<Listing[]>;