Questions tagged [switchmap]

Questions about switchMap operator, an RxJS flattening operator to handle observables and emit values.

switchMap is an RxJS flattening operator to handle observables and emit values. Used in coding reactive web pages.

This operation works well to handle observables, where there is no need to ensure that the call has succeeded, only returning the value from the latest call.

Related tags:

195 questions
0
votes
1 answer

Implementing rxjs switchmap in angular

This is older implementation and I wanted to get HeatingDesired value //1st api call this.siteService.getScheduleParamsByRoomRef('temp and air and desired and heating', this.refs.roomRef).subscribe(({ rows }) => { if (rows.length > 0) { …
Enthu
  • 512
  • 2
  • 13
  • 38
0
votes
1 answer

RXJS SwitchMap not repeating a request after it has been cancelled

switchMap does not repeat HTTP calls. I have created a directive that validates an email if it already exists. Inside that directive, is an API. Every time a keypress happens, the API is being called to check if it already exists. I'm using…
user12020633
0
votes
1 answer

Angular Rxjs Multiple Parallel HTTP Requests / Calls blocking navigation - Priority Cancel Queue Concurrent

i know there are similiar threads but there isnt one that provided a fitting solution for my problem. Pre: I am navigating on the server side and on the client side at the same time. That means every navigation on the frontend with routerLink and…
liqSTAR
  • 1,225
  • 1
  • 12
  • 22
0
votes
1 answer

RXJS Observable unexpectedly completes after first run through pipe

I have an Angular app with a persistent store and a list of keys for storage items. I want to load the values for the known keys from the persistent store into memory asynchronously at app start, so that they can be accessed synchronously while the…
tosi
  • 787
  • 1
  • 7
  • 12
0
votes
0 answers

How to cancel previous http request in Angular using Rxjs operators

I am trying to cancel any pending request using Rxjs. I have gone through some of docs/blogs which suggested to make use of SwitchMap() and debounceTime() operator. I am trying the same but unable to cancel the previous pending request. In my case I…
shreyansh
  • 1,637
  • 4
  • 26
  • 46
0
votes
1 answer

Angular 6 RxJS chain multiple dependant subscriptions

I'm hoping someone can offer a little advice on how to do the following: I have a requirement to chain multiple http requests with each one dependant on the result of the previous. i.e Step 1: Login User Step 2: Authenticated Http request Step 3:…
ledragon
  • 299
  • 6
  • 17
0
votes
1 answer

RXJS v6.4 switchMap operator returns an Observable rather than the result (accordinng to TypeScript linter)

I am running an Angular 8 app, and I am getting an error which seems to be a major bug in RxJS or I am missing something. import { of } from 'rxjs'; import { switchMap } from 'rxjs/operators'; of(1,2,3) .pipe( switchMap((x) => of(x + 1)) …
DoubleA
  • 1,636
  • 14
  • 28
0
votes
0 answers

Angular 7 switchMap calling Twice

I have been trying to get this to work with just one request. But when the function calls the service it fires the get request twice. If I remove the switchMap it fires once. The http request is fired twice it should only fire once. Any help is…
Natdrip
  • 1,144
  • 1
  • 11
  • 25
0
votes
1 answer

No instance(s) of type variable(s) Y exist so that Calendar conforms to LiveData

I want my LiveData instance to change everytime List of Alarms change. I have following code: private LiveData nextAlarm; public MyViewModel(@NonNull Application app) { nextAlarm =…
Tom11
  • 2,419
  • 8
  • 30
  • 56
0
votes
1 answer

Why onComplete not fired when an infinite stream is switchMap'ed

Using RxJava 2.2.8: Observable.fromCallable(() -> "Some data") .subscribe( s -> System.out.println(s), e -> System.err.println(e), () -> System.out.println("Completed") …
kmansoor
  • 4,265
  • 9
  • 52
  • 95
0
votes
0 answers

rxjs: gradually fetch value as user moves slider, sending new requests after previous completed

Goal: User moves the slider, and the slider value is sent to the server to calculate some value X, displayed next to the slider and updated gradually as slider value changes. What I did: used throttled Subject, switchMap'ped to fetch the…
eagor
  • 9,150
  • 8
  • 47
  • 50
0
votes
1 answer

Error trying to diff '...'. Only arrays and iterables are allowed. (Using switchMap)

So I'm studying Angular and I'm working on a project with Spotify API. When I search for music I'm getting this error (Error trying to diff 'A$AP Twelvyy'. Only arrays and iterables are allowed). I want to use switchMap since the event triggers with…
0
votes
1 answer

RxJS 6 - Angular 7 - Properly canceling current http request from subject

Hi I am having trouble with my subject subscription and my search call. I want to cancel the previous call in favor of the current one. I have search through previous threads but have not had success with finding an answer. I know I am supposed to…
Natdrip
  • 1,144
  • 1
  • 11
  • 25
0
votes
1 answer

Asynchronous API calls issue : Iterate First Response and pass value to make another API call in Angular 6

I am java developer, trying to work with Asynchronous API calls which needs to be called synchronously. I need to make first API call >> iterate response as array >> make another API call >> return response of last API call and subscribe…
ronypatil
  • 153
  • 2
  • 3
  • 19
0
votes
1 answer

Problem with emit after switchMap angular observable

The problem is: when this.getPost())) return error eg 404 (it's function which return GET), then code this.loggedChange.emit(false) is not executed and I don't know why. After this situation I have wrong output of loggedChangedHandler. It's look…
emka26
  • 433
  • 1
  • 11
  • 28