I'm trying to combine 2 Observable streams to 1 stream with combineLatest
.
Only, the .map()
function doesn't work on the resulting stream. And with doesn't work, I mean that nothing is logged in the example below. On the other had, if I switch out the .map()
function for a .subscribe()
function, then everything works just fine. My observables come from firebase using the angularfire2
library. I have also imported the map
function and it works on other Observable streams.
const placeList = this._db.list(URL)
.map(this.flattenJSON);
const placeImages = this._db.list(URL);
Observable.combineLatest(placeList, placeImages)
.map(response => {
console.log(response);
return response;
});
Does anyone know why the subscribe
function works, and the map
does not? And does anyone have advice on how I can merge 2 firebase Observable streams and map this stream. Mind you that the Observable streams resulting from angularfire2
do not finish.
You should always subscribe to an observable if you want it to actually get executed. Just chain subscribe()
after the map:
const placeList = this._db.list(URL)
.map(this.flattenJSON);
const placeImages = this._db.list(URL);
Observable.combineLatest(placeList, placeImages)
.map(response => {
console.log(response);
return response;
})
.subscribe();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With