I'm trying to combine two observables, one of em being route params and the other one a custom one.
I'm using zip
because forkJoin
doesn't seem to work. But the zip is acting strange, cuz when I emit my custom one I don't get that value. I only get the first null value which has been given to my BehaviorSubject
as a default emit value.
I read this
"The zip operator will subscribe to all inner observables, waiting for each to emit a value. Once this occurs, all values with the corresponding index will be emitted. This will continue until at least one inner observable completes."
Does that mean that it won't respond until both of the observables emit a value? Because the route params observable will only emit once, but the dataEmitter
will continue to emit values. What would be the correct operator to use in this case?
Here's some of my code:
Emitter in my service:
private dataEmitter: BehaviorSubject<any> = new BehaviorSubject<any>(null);
Component subscription, only get null
from the dataEmitter
, never this.calculatedData
:
Observable.zip(this.route.params, this.dataCalculator.dataEmitter$)
.subscribe(data => console.log(data));
This is called when all of the calculations have been done:
this.dataEmitter.next(this.calculatedData);
As pointed out by @cartant switching to combineLatest
works as expected:
Observable.combineLatest(this.route.params, this.dataCalculator.dataEmitter$)
.subscribe(data => console.log(data));
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