Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to transform a Subject into an Observable in RxJs 5

Tags:

rxjs

rxjs5

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
like image 233
Angular University Avatar asked Jan 29 '16 21:01

Angular University


1 Answers

FYI: Subject.prototype.asObservable() will be in the next release 5.0.0-beta.2.

At that point, you can just call mySubject.asObservable().

like image 83
Ben Lesh Avatar answered Jan 03 '23 18:01

Ben Lesh