How to convert an Observable into a BehaviorSubject?

No need to convert it. Just create a subject and attach observable to it with : obs.subscribe(sub) example: var obs = new rxjs.Observable((s) => {setTimeout(()=>{s.next([1])} , 500)}) //observable var sub = new rxjs.BehaviorSubject([0]) //create subject obs.subscribe(sub) //<—– HERE —– attach observable to subject setTimeout(() => {sub.next([2, 3])}, 1500) //subject updated sub.subscribe(a => console.log(a)) //subscribe to … Read more

What is the difference between BehaviorSubject and Observable?

BehaviorSubject is a variant of Subject, a type of Observable to which one can “subscribe” like any other Observable. Features of BehaviorSubject It needs an initial value as it must always return a value upon subscription, even if it has not received the method next() Upon subscription, it returns the last value of the Subject. … Read more

What is the difference between Subject and BehaviorSubject?

A BehaviorSubject holds one value. When it is subscribed it emits the value immediately. A Subject doesn’t hold a value. Subject example (with RxJS 5 API): const subject = new Rx.Subject(); subject.next(1); subject.subscribe(x => console.log(x)); Console output will be empty BehaviorSubject example: const subject = new Rx.BehaviorSubject(0); subject.next(1); subject.subscribe(x => console.log(x)); Console output: 1 In … Read more

BehaviorSubject vs Observable?

BehaviorSubject is a type of subject, a subject is a special type of observable so you can subscribe to messages like any other observable. The unique features of BehaviorSubject are: It needs an initial value as it must always return a value on subscription even if it hasn’t received a next() Upon subscription, it returns … Read more