How to handle error in a Resolver

Here is an example of one of my resolvers with error handling, using the technique that Gunter suggests: import { Injectable } from ‘@angular/core’; import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from ‘@angular/router’; import { Observable } from ‘rxjs/Observable’; import ‘rxjs/add/operator/catch’; import ‘rxjs/add/operator/map’; import ‘rxjs/add/observable/of’; import { IProduct } from ‘./product’; import { ProductService } … Read more

Reactive Programming – RxJS vs EventEmitter in Node.js

Observables are not like EventEmitters. They may act like EventEmitters in some cases, namely when they are multicasted using RxJS Subjects, but usually they don’t act like EventEmitters. In short, an RxJS Subject is like an EventEmitter, but an RxJS Observable is a more generic interface. Observables are more similar to functions with zero arguments. … Read more

Subscribe to both route params and queryParams in Angular 2

I managed to get a single subscription to both the queryParams and Params by combining the observables by using Observable.combineLatest before subscribing. Eg. var obsComb = Observable.combineLatest(this.route.params, this.route.queryParams, (params, qparams) => ({ params, qparams })); obsComb.subscribe( ap => { console.log(ap.params[‘type’]); console.log(ap.qparams[‘page’]); });

In Angular rxjs when should I use `pipe` vs `map`

The “new” way, using pipe, is called Lettable Operators Pipeable Operators. The “old” way, where you chain operators, is called using “patch operators”. Starting in version 5.5 we have shipped “pipeable operators”, which can be accessed in rxjs/operators (notice the pluralized “operators”). These are meant to be a better approach for pulling in just the … Read more

What is the difference between Rx.Observable subscribe and forEach

In the ES7 spec, which RxJS 5.0 follows (but RxJS 4.0 does not), the two are NOT the same. subscribe public subscribe(observerOrNext: Observer | Function, error: Function, complete: Function): Subscription Observable.subscribe is where you will do most of your true Observable handling. It returns a subscription token, which you can use to cancel your subscription. … Read more

Using shareReplay(1) in Angular – still invokes http request?

If you call every time this.http.get(API_ENDPOINT).pipe(shareReplay(1)), each time http request will be triggered. If you want to make http call once and cache data, the following is recommended. You first get the observable for data: ngOninit(){ this.data$ = this._jokeService.getData().pipe(shareReplay(1)); } Now subscribe multiple times: public getData(){ this.data$.subscribe(); } Your service: public getData() { return this.http.get(API_ENDPOINT) … Read more

RxJS – Multiple sources for .withLatestFrom

withLatestFrom supports multiple observables: .withLatestFrom(source1, source2, source3) .map((data) => { console.log(data) }); -> [val, value1, value2, value3] It also supports function as it’s last parameter, so you can get values other than arrays: observable$ .withLatestFrom(source1, source2, (val, one, two) => { return {val: val, one: one, two: two}; });

Best way to “flatten” an array inside an RxJS Observable

You can use concatAll() or mergeAll() without any parameter. dataFromBackend.pipe( tap(items => console.log(items)), mergeAll(), // or concatAll() ) This (including mergeMap) works only in RxJS 5+ because it treats Observables, arrays, array-like objects, Promises, etc. the same way. Eventually you could do also: mergeMap(val => from(val).pipe( tap(item => console.log(item)), map(item => item.name), )), toArray(), Jan … Read more

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

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