rxjs

How to handle an empty result with rxjs observable

╄→гoц情女王★ 提交于 2019-12-25 01:02:34
问题 I have an API that might return [] result. HTTP/1.1 200 OK Date: Tue, 16 Apr 2018 06:06:22 GMT Content-Type: application/json; charset=utf-8 Server: Kestrel Transfer-Encoding: chunked Request-Context: appId=cid-v1:... [] Here is my code that just does not work in that particular case: getData(): Observable<Thing[]> { return this.getData1() .pipe( flatMap(aData => { const ids = aData.map(({ id }) => id); const bData = this.getBData(ids); // emty result might be here //test subscribe this

Diffing two Observables

我只是一个虾纸丫 提交于 2019-12-25 00:54:12
问题 I'm looking for a best way to Diff two Observables. Filtered values from ObservableA should be emited as soon as ObservableB completes without waiting for ObservableA to complete. <html> <head> <title></title> <script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.3.0/Rx.js"></script> <script> const observable_a = Rx.Observable.interval(2000).take(10);//0,1,2,3,4,5,6,7,8,9 const observable_b = Rx.Observable.interval(1000).map(x=>x+3).take(5);//3,4,5,6,7 someDiffObservable(observable_a

Angular RXJS CatchError in Heroes tutorial

こ雲淡風輕ζ 提交于 2019-12-25 00:38:21
问题 I'm running the Angular tutorial and I can't understand what is actually happening in one section. I've found some examples from searching, but nothing specifically answers this question. Here is the code: getHeroes (): Observable<Hero[]> { return this.http.get<Hero[]>(this.heroesUrl) .pipe( catchError(this.handleError('getHeroes', [])) ); } Next is the error handler it calls: /** * Handle Http operation that failed. * Let the app continue. * @param operation - name of the operation that

how to send independent http request in sequence angular

心已入冬 提交于 2019-12-25 00:38:10
问题 I want to send 10 requests that are independent, one after the other in sequence. and want to get all the results in an array. I have tried forkJoin but it hit all the requests in parallel. For parallel requests search(queryUrls) { queryUrls.forEach((query) => { observableBatch.push(this.http.post(query.url, query.data)) .pipe( map((res) => res), catchError(e => of('Error')) ); }); // return forkJoin(observableBatch); } and I can subscribe this method and can get all the results in an array.

Angular rxjs. combine multiple observables

旧时模样 提交于 2019-12-25 00:29:36
问题 I have 2 observables: this.configsService.getConfigsList() this.bcProductService.getProductById(config['id']) I can subscribe to both of them and use their data. I want to get the configs list and map each config item with its corresponding product (using the config.id)... Something like this. const configs = this.configsService.getConfigsList; const product= (id)=> this.bcProductService.getProductById(id); configs.pipe( concatMap(val => product(val['id']).map(t=>val['p']=t) ) ).subscribe

How to send a boolean from a http request to a component?(Angular)

梦想的初衷 提交于 2019-12-24 23:16:06
问题 I created a program with Angular 7 and i want to catch the http request in a boolean and to transfer it to a component. I tried to use BehaviourSubject with next for this. So the boolean has to be true inside these two functions checkin() and checkOut(). I attached the code. I would appreciate any help. Thanks! import { Component, OnInit } from '@angular/core'; import { HttpLoadingInterceptor } from '../../../interceptor/http-loading.interceptor'; import { Subscription } from 'rxjs';

RxJs move array of objects to root array

旧城冷巷雨未停 提交于 2019-12-24 23:06:38
问题 I am getting below set of data via Observable [ 0: {id: "12321", itemName: "Item 1", category: "All"}, 1: [ 0: {id: "423423", itemName: "Sub Item 1", category: "subcat"}, 1: {id: "413212", itemName: "Sub Item 2", category: "subcat"} ], 2: {id: "65655", itemName: "Item 2", category: "All"}, 3: {id: "87877", itemName: "Item 3", category: "All"}, 4: [ 0: {id: "354345", itemName: "Sub Item 1", category: "subcat"}, 1: {id: "123434", itemName: "Sub Item 2", category: "subcat"}, 2: {id: "765767",

Returning the result of a forkJoin from an ngrx/store effect

↘锁芯ラ 提交于 2019-12-24 22:42:47
问题 I am trying to return the result of a forkJoin in my effect using ngrx store, like this pseudocode demonstrates: @Effect() someEffect$: Observable<Action> = this.action$.pipe( ofType<SomeActionType>(ActionTypes.SomeActionType), switchMap((action: any) => this.http.get<any>('some/url').pipe( map(someResult => { // this implementation is unimportant, just the gist of the flow I'm after const potentialResults = oneOrMany(someResult); if( potentialResults.length === 1 ) { return new SomeAction

Angular getting Authorization token asynchronously before HTTP calls

こ雲淡風輕ζ 提交于 2019-12-24 21:33:27
问题 before posting this i went to many other similar questions and not able to find solutions. like Angular 2 - Inject authorization token before each Http request I am using AWS session which provides me Authorization token for makeing HTTP request. Now getting session can be asynchronous operation depending on need to refresh token. Problem: I am not able to chain getting session and then making HTTP calls. Versions Angular 5, RxJs 5.5.2 AuthService's get session function. getSession():

convert rjxs map and flatten/reduce to flatMap

心不动则不痛 提交于 2019-12-24 20:55:34
问题 I believe the following code can be refactored using a flatMap but I cant seem to get it working as desired. I understand flatMap essentially maps and then flattens, which is perfect for me as I'm using forkJoin so get an array of responses back from getAutocompleteSuggestions(). I want a single array of results upon subscription (which is what the code below produces), but changing the top level map to flatMap sends multiple single objects to the subscription. How can this code be better