Merge subarrays using Observables

Provided it is a typo and the second element has subItems as well (and not searchProfiles), you don’t need flatMap or any thing of the sort, you can do it in a plain map using js array operators: var transformed = [].concat(…result.map(item => item.subItems)); or in your case httpResult$.map(result => [].concat(…result.map(item => item.subItems)) if the … Read more

Subscribing to a nested Observable

I’d do it like the following: function mockRequest() { return Observable.of(‘[{“id”: 1}, {“id”: 2}, {“id”: 3}]’); } function otherMockRequest(id) { return Observable.of(`{“id”:${id}, “desc”: “description ${id}”}`); } class ItemsService { fetchItems() { return mockRequest() .map(res => JSON.parse(res)) .concatAll() .mergeMap(item => this.fetchItem(item)); } fetchItem(item: Item) { return otherMockRequest(item.id) .map(res => JSON.parse(res)); } } let service = new … Read more

How to correctly import operators from the `rxjs` package

There are static and instance operators in RxJS: static of interval instance map first You may want to use these on the Observable global object or observable instance like this: Observable.of() observableInstance.map() For that you need to import modules from the add package: import ‘rxjs/add/observable/of’ import ‘rxjs/add/operator/map’ When you import the module it essentially patches … Read more

ngrx effects error handling

The ngrx infrastructure subscribes to the effect via the provider imported into the app’s NgModule using EffectsModule.run. When the observable errors and catch returns a empty obervable, the composed observable completes and its subscribers are unsubscribed – that’s part of the Observable Contract. And that’s the reason you see no further handling of LOGIN actions … Read more

Rxjs Retry with Delay function

delay() is used to introduce a delay between events emitted by the observable. But the observable never emits any event. It just errors immediately. What you’re looking for is retryWhen(), which allows deciding after how long to retry: RxJS 5: .retryWhen(errors => errors.delay(1000).take(10)) RxJS 6: import { retryWhen, delay, take } from ‘rxjs/operators’ someFunction().pipe( // … Read more

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