Angular RxJS Observable: takeUntil vs. unsubscribe with a Subscription [closed]

Option 1: clean & explicit. Works like a charm Option 2: more procedural, less stream-like. Works like a charm. Note that your stream will not get a ‘complete’ event which can cause unexpected behaviour Option 3: takeWhile – will have the subscription stay around untill an emission is created and then the takeWhile is evaluated. … Read more

Angular2 Query Params Subscription Fires Twice

Router observables (as another answer mentions) are BehaviorSubject subjects, they differ from regular RxJS Subject or Angular 2 EventEmitter in that they have the initial value pushed to the sequence (an empty object in the case of queryParams). Generally the possibility of subscribing with initialization logic is desirable. The initial value can be skipped with … Read more

Filter an observable using values from another observable

You can use withLatestFrom. . source.withLatestFrom(checkboxes, (data, checkbox) => ({data, checkbox})) .filter(({data, checkbox}) => …) Here, checkboxes is an observable representing a list of checkbox inputs. source is an observable representing a stream of events coming from the server. In the filter function you can check if the data is valid compared to the checkbox … Read more

How can I console.log the value of a observable?

With a regular observable you only get the value when it changes, so if you want to console.log out the value you will need to console.log it in the subscription: constructor( private store: Store<any> ) { this.count = this.store.select<any>(state => state.count); this.count.subscribe(res => console.log(res)); } However if you are wanting to be able to get … Read more

Angular2 Observable and Promise

When you call subscribe(…) a Subscription is returned which doesn’t have a toPromise(). If you move the code from subscribe to map you can use toPromise() instead of subscribe return this._httpClient.post(‘LoginAction’, credentials) .map(res => res.json()) .map(user => { return new User(user); }).toPromise(); and the caller will get a Promise where he can get the value … Read more

How to pass results between chained observables

You certainly shouldn’t have your methods take in params that don’t concern them! To your main question: How to pass results between chained observables without the problems i’ve mentioned? Use a single scope (nested pipes) The code below is equivalent to your sample code, with no need to pass the unnecessary properties. The previously returned … Read more

Split Rx Observable into multiple streams and process individually

Easy as pie, just use filter An example in scala import rx.lang.scala.Observable val o: Observable[String] = Observable.just(“a”, “b”, “c”, “a”, “b”, “b”, “b”, “a”) val hotO: Observable[String] = o.share val aSource: Observable[String] = hotO.filter(x ⇒ x == “a”) val bSource: Observable[String] = hotO.filter(x ⇒ x == “b”) val cSource: Observable[String] = hotO.filter(x ⇒ x == … Read more

RxJS takeWhile but include the last value

Since RxJS 6.4.0 this is now possible with takeWhile(predicate, true). There’s already an opened PR that adds an optional inclusive parameter to takeWhile: https://github.com/ReactiveX/rxjs/pull/4115 There’re at least two possible workarounds: using concatMap(): of(‘red’, ‘blue’, ‘green’, ‘orange’).pipe( concatMap(color => { if (color === ‘green’) { return of(color, null); } return of(color); }), takeWhile(color => color), ) … Read more

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