switchmap

Rxjs conditional switchMap based on a condition

微笑、不失礼 提交于 2021-01-21 18:12:46
问题 I have a situation like the following: myObservable1.pipe( switchMap((result1: MyObservable1) => { if (condition) { return myObservable2; } else { return of(null); } }) ).subscribe(myObservable1 | myObservable2) => { So if condition is false I only have to perform one request, if the condition is true, I have to chain the first request to the following one, they are essentially two requests to the server api. Is there a better solution without returning that null ? Is there any conditional

Rxjs conditional switchMap based on a condition

喜欢而已 提交于 2021-01-21 18:12:22
问题 I have a situation like the following: myObservable1.pipe( switchMap((result1: MyObservable1) => { if (condition) { return myObservable2; } else { return of(null); } }) ).subscribe(myObservable1 | myObservable2) => { So if condition is false I only have to perform one request, if the condition is true, I have to chain the first request to the following one, they are essentially two requests to the server api. Is there a better solution without returning that null ? Is there any conditional

RxJs switchMap with angular HttpClient

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-19 00:56:49
问题 I have a use case whenever a new request is triggered, any http requests that are already in flight should be cancelled / ignored. For eg : A request (say #2) comes in while the request #1 takes too long to respond / slow network connectivity. In this case #2 gets a very quick response from server then at any point even if the #1 comes back with a response the HTTP response observable should be ignored. The problem i face is, first the component displays response values from request #2 and

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():

how to use switchMap to cancel pending http requests and taking the last subscribe only?

拜拜、爱过 提交于 2019-12-02 08:31:49
问题 i tried canceling pending http request using subscription.unsubsribe like this: getAgentList(pageNumber: number, filter: string): any { let requestUrl: string = 'api/service/agents_search?ACCT=' +this.accountId; if ( this.subscription ) { this.subscription.unsubscribe(); } this.subscription = this.backEndCommService.getData(requestUrl) .subscribe( (res: any) => { let serverResponse: ServerResponse = new ServerResponse(this.accountId, pageNumber, res.search_results, res.resultRows, res