Is the startWith operator in RXJS really deprecated?

No, it is not. Currently there is only one active signature: startWith(…values) Apart from this signature, it has several overloads which accept scheduler: SchedulerLike as the latest parameter: startWith(…values, scheduler) and this functionality has been deprecated. If you don’t use scheduler with startWith you are fine. If you do, then you need rewrite your code … Read more

Angular 2: why use switchMap when retrieving route params?

switchMap is usually used when you have some async operation that is triggered by some prepended “event/stream”. The difference to e.g. flatMap or concatMap is, that as soon as the next trigger emits, the current async operation is canceled and re-triggered. In your case this means, that as soon as the route-params change, your hero-service … Read more

SwitchMap vs MergeMap in the #ngrx example

You are correct; switchMap will unsubscribe from the Observable returned by its project argument as soon as it has invoked the project function again to produce a new Observable. RxJs is incredibly powerful and dense, but its high level of abstraction can sometimes make code hard to understand. Let me debunk the marble diagrams and … Read more

How to pass observable value to @Input() Angular 4

Assume DynamicFormService.getAnswers(‘CAR00PR’) is asynchronous(probably it is), using async Pipe to pass asynchronous result is on the right way, but you cannot expect to get the asynchronous result right now when DynamicFormComponent is created(at ngOnInit) because of Asynchonous. The result isn’t ready yet when running your below line of code. this.form = this.qcs.toFormGroup(this.answers); There are several … Read more

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

Multiple subscriptions to Observable

Subject In your case, you could simply use a Subject. A subject allows you to share a single execution with multiple observers when using it as a proxy for a group of subscribers and a source. In essence, here’s your example using a subject: const subject = new Subject(); function trigger(something) { subject.next(something); } subject.subscribe((x) … Read more

RxJs pipe and lettable operator `map`: ‘this’ context of type ‘void’ is not assignable to method’s ‘this’ of type ‘Observable’

Lettable instance operators should be imported from rxjs/operators: import { map } from ‘rxjs/operators’; As opposed to non-lettable equivalents which are imported from rxjs/operator: import { map } from ‘rxjs/operator/map’; To learn more about lettable operator read: RxJS: Understanding Lettable Operators