Previously in rxjs4 there was a method in the BehaviorSubject called:
getValue()
(doc here).
This method does not exist anymore in rxjs5.
So the only solution that I found to get the value of a BehaviorSubject was:
let value;
myBehaviorSubject.take(1).subscribe( (e) => value = e );
This code runs synchronously (I do not exactly understand why, but it does ...) and gets the value. It works, but it's not as clean as it could be if getValue()
was present:
let value = myBehaviorSubject.getValue();
Why getValue()
was removed in rxjs5 and what's the cleanest solution to this problem?
BehaviorSubject
interface has been simplified - the getter is called just.value
. – Unblushingof
and notBehaviorSubject
– Occlusion