rxjs

Is there an operator that works as concatMap but with more than one inner observables

无人久伴 提交于 2019-12-24 07:15:39
问题 I'm using an observable to query my DB. This observable will return an array with all the matching objects found. My problem is that I want to map the observable with more details that I will retrieve from another API. I tried concatMap but it only let me nest 1 observable inside the initial observable const usersAPI$: Observable<Users[]> = // something const assistsAPI$: Observable<Assists[]> = // something const modifiedAssists$ = assistsAPI$.find().pipe( concatMap(assists => assists.map

angular 2 refresh token before custom http request

百般思念 提交于 2019-12-24 07:01:05
问题 I want to refresh the token before the custom http request if it is expired. I try my code when I'm sure that the token is expired but it gives the following console result: Token refresh is required app.js:1:92855 updateToken() method inside app.js:1:93301 tokenNotExpired?: false app.js:1:92674 Token refresh is required app.js:1:92855 updateToken() method inside app.js:1:93301 tokenNotExpired?: false app.js:1:92674 Token refresh is required app.js:1:92855 updateToken() method inside app.js:1

retryWhen with backoff

拟墨画扇 提交于 2019-12-24 06:44:49
问题 Trying to retry (with backoff logic) when error on http.get return this.http.get(this.urlToBackend) .map((res: Response) => res.json()) .retryWhen(errors => errors .zip(Observable.range(3, 15), (_, i) => i) .flatMap(i => { if (i >= 15) { throw errors; } let t = (Math.pow(2, i)) * 1000; return Observable.timer(t); })) .catch((error: any) => this.handleError(error, false, 0, this.urlToBackend)); Keep getting this error: TypeError: this.http.get(...).map(...).retryWhen is not a function at

Angular HttpInterceptor not working with forkJoin

99封情书 提交于 2019-12-24 06:43:55
问题 I have Service to get the token from type Observable and HttpInterceptor to use it to inject the token in every http request. The thing is it works fine with a single request but if i used forkJoin i will not get any response back. the interceptor code import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable, } from 'rxjs'; import { catchError, map, switchMap } from 'rxjs

Why are my interval polling requests occurring only once?

霸气de小男生 提交于 2019-12-24 06:42:00
问题 I am trying to make a simple polling service using rxjs and angular 7 and am running into a recurring issue that my requests are only actually being fired once but the interval completes successfully with no errors. My service component looks like this: import { HttpClient, HttpHeaders, HttpRequest } from '@angular/common/http'; import { interval, Subject } from 'rxjs/index'; import { exhaustMap } from 'rxjs/internal/operators'; constructor( private httpClient: HttpClient ) { } getPing() {

Initialize cache when it is used

我的梦境 提交于 2019-12-24 05:37:09
问题 Lets say that I have the following events: DoSomething FetchSomething FetchSomethingSuccessful DoSomething does something that needs some cached data. When I fire off the event I want to look in the cache and do something with it if it exists. If it doesn't then I want to fetch it, wait for it to be in cache, and try again. I came up with the following solution but it feels like I'm abusing the map operator. Is there a more appropriate operator to use to observe the stream and throw an error

How to combine two firebase collections into a new array of objects

烈酒焚心 提交于 2019-12-24 05:16:26
问题 I'm working on a small project with Angular and Firebase. When a date is changed I need to get a list of "Questions" that have been created, on or before that date as well as a single "Answer" of that Question for that day. The current date is a BehaviorSubject so when it changes I use a switchmap to get the list of Questions and Answers for that date. But it seems after using forkJoin and map to combine/merge the two array's into one nothing is displayed on my page. But if I simply return

My NgRx effects not working, nothing happend

北城以北 提交于 2019-12-24 05:15:05
问题 I have problem with my NgRx effects. The application correctly adds to the store, unfortunately my effects with the request are not performed, i.e. at the time of launching the addition of a new car, add it to the store and that's it. The problem is that there are no console logs from my effects, no http error because of the wrong url, nothing at all. My app code: Reducer import { Action } from '@ngrx/store'; import * as CarActions from './car.actions'; import { Car } from 'src/models/car

Subject Subscription is triggered twice when I call .next() once in Angular app

谁说我不能喝 提交于 2019-12-24 03:41:23
问题 i'm trying to create a reusable Modal component. in a ModalService i have a Subject, and a method that that calls next() on the subject. The ModalComponent subscribes to that subject, but whenever the method in the service is being called, the next function of the observer gets triggers twice. Anyone know what causes this? export class ModalService { openModal = new Subject(); constructor() { } open(cmp) { this.openModal.next(cmp); } } Modal Component: export class ModalComponent implements

Having trouble calling RxJS share using the recommended operator import

落花浮王杯 提交于 2019-12-24 02:56:12
问题 I'm trying to understand the best practice for importing rxjs operators It seems like I should import share this way, but, the following doesn't work because it says share expects 0 arguments. I'm not quite sure how to call share correctly. import { share } from 'rxjs/operators'; ... public currentUser: Observable<User> = share(this.currentUser$.asObservable()); Doing it the old way causes no problems. However I seemed to have read that's not the preferred way to import https://www.learnrxjs