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

Angular 2 Observable with multiple subscribers

I encountered a similar problem and solved it using Aran’s suggestion to reference Cory Rylan’s Angular 2 Observable Data Services blog post. The key for me was using BehaviorSubject. Here’s the snippets of the code that ultimately worked for me. Data Service: The data service creates an internal BehaviorSubject to cache the data once when … Read more

Simple way to get the current value of a BehaviorSubject with rxjs5

As was pointed out by artur grzesiak in the comments, the BehaviorSubject interface was cleaned up, and the getter is now just myBehaviorSubject.value. I just wanted to add this as an answer because I almost didn’t read the comments to the original question, and would have missed the correct answer.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)