How can we transform a Subject into an Observable in RxJs 5 ? This functionality is useful for example when we want to expose the Subject for subscription but don't want to yield control of calling next()
on it, and prefer to keep the issuing of new values private.
The docs (see here) mention something like this:
var subject = new Rx.Subject();
var obs = subject.asObservable();
But in RxJs 5 this currently does not work (alpha 8), we get the following error:
"TypeError: subject.asObservable is not a function
FYI: Subject.prototype.asObservable()
will be in the next release 5.0.0-beta.2
.
At that point, you can just call mySubject.asObservable()
.
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