Solution for AngularFireAuth.user observable won’t emit when placed in withLatestFrom RxJS operator
is Given Below:
AngularFireAuth.user observable works fine if it is the source observable e.g.
this.AngularFireAuth.user.subscribe((u) => console.log(u))
but blocks my observable stream if I place it in the
withLatestFrom operator, e.g.
of("test") .pipe( tap(console.log), // log showing up withLatestFrom(this.AngularFireAuth.user), tap(console.log) // log not showing up ).subscribe()
What am I doing wrong and how can I get around it? I need the current auth state but the source observable needs to be a different observable than that.
that is because user stream didn’t emit anything yet. I believe the easiest case to fix this problem would be to add
startsWith(null) for the user stream
AngularFireAuth.user probably has no emition during the usage of
You could use the
combineLatest operator. The operator emit latest values when one of the passed observables emit. In your case this is the
of("test") .pipe( tap(console.log), // log showing up combineLatest(this.AngularFireAuth.user), tap(console.log) // log not showing up ).subscribe()
Combines multiple Observables to create an Observable whose values are
calculated from the latest values of each of its input Observables.