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

SWITCHMAP operator throws error when used with ParamMap

I'm trying to get data by special types. So I use 2 observables. this.activatedRoute.paramMap .pipe( takeWhile(() => this.alive), switchMap((params: ParamMap) => this.setProductStatus(params.get('status')) ) …
gogi15
  • 1
  • 1
0
votes
0 answers

No change detection in Angular when change is in switchMap

I have two components Parent and child. In parent there is HTTP call and there is a switchMap operator. Inside the loading status has changed as above: this.subscriptions.add(this.personService.updatePerson(this.personId, personobject.list) …
ruddnisrus
  • 187
  • 5
0
votes
1 answer

Wait for Promise to resolve before result is used in switchMap

I have the following code which works intermittently. Sometimes the getCurrentPosition promise does not resolve in time, and undefined gets passed to the first switchMap in my pipe, which breaks everything of course. Location Service: // Get…
0
votes
1 answer

Angular subscription to switchMap() function does not wait for setInterval() and returns undefined

This is the function which subscribes to the switchmap mintNft(): void { this.__mmservice.mintNft().subscribe({ next: (response: any) => { console.log(response, 'next response') }, error: (response: any) => { …
sbsb3
  • 23
  • 5
0
votes
0 answers

switchMap gives error type 'void' is not assignable to type 'ObservableInput

I have a variable queryCode of type string that depends on the value of route params so it is set under subscribe of activated route params and then using that value if it's null or not I call several other services. I tried to use switchMap since…
oescc
  • 37
  • 1
  • 6
0
votes
1 answer

Cancel only specific pending HTTP request with RXJS switchMap

I am trying to solve the following use case, but the more I read the more confused I get. Perhaps someone could show me the right direction. Let's say I have some sort of javascript service that is called by some client and triggers a calculation…
Florian
  • 1,142
  • 1
  • 9
  • 21
0
votes
2 answers

Angular - improve my autocomplete with switchMap

At the moment I have the following setup : In my component : /**/ onCitySearch() { this.citiesService.getCities(this.citySearchControl.value); } In my service : /**/ getCities(term: string) { if (term.length < 3 || term ===…
Nite
  • 323
  • 1
  • 4
  • 12
0
votes
1 answer

RXJs Switch Map flow and API cancellation

I am working on an existing Angular application and there is an issue where the APIs keep getting cancelled sometimes. It is mostly happening on Development site but not on local. somefunctionName(x) { this.service.serviceFunction(x.id,…
0
votes
1 answer

Angular - run SwitchMap on condition

I have the code below: data$ = getResponse1$.pipe( tap((res1: any) => { this.qService.data = res1; }), switchMap(() => of(getResponse2$(res2)).pipe( map((val) => { const res: any…
0
votes
1 answer

Angular|RxJS - Type-ahead search request gets cancelled by browser (on click)

I am new to RxJS (and frontend) but I know that switchMap() in the following code is used to break and re-run a search request as the user types into a text box. Search works fine, the only problem is that if the user clicks anywhere outside the…
bigShaq
  • 69
  • 11
0
votes
1 answer

switchmap and forjoin operator in angular

hi everyone I have a problem I try to explain it in the best possible way (I also created a stackblitz where I reproduce the code) I am using jsonplceholder. I make a first http get call to this url jsonplaceholder.typicode.com/users and I get an…
michelemalagnini
  • 149
  • 2
  • 10
0
votes
1 answer

Angular - How to get posts, tags and comment count from Wordpress REST API using switchMap and then combine the resulting values using JavaScript?

I am working on an Angular app that needs to fetch posts, their respective tag names and comment count from Wordpress REST API. With the API three GET requests need to be sent to the server. The first request is being sent to /wp/v2/posts. The…
aleksejjj
  • 1,405
  • 2
  • 18
  • 28
0
votes
1 answer

Angular - How to get posts and tag names from Wordpress REST API using switchMap (merge two server responses)?

I am working on an Angular app that needs to fetch posts and their respective tag names from Wordpress REST API. With the API two GET requests need to be sent to the server. The first request is being sent to /wp/v2/posts. The response from the…
aleksejjj
  • 1,405
  • 2
  • 18
  • 28
0
votes
1 answer

How to test RxJS switchMap with Jasmine in Angular?

In my Angular project I have this code in one of my components: delete(post: PostInterface): void { const delete$ = this.appDataService.proxy .delete(post, this.paginate) .pipe(switchMap(() => this.loadDatas())); …
netdjw
  • 5,419
  • 21
  • 88
  • 162
0
votes
3 answers

Performing multiple API calls before dispatching an Action an NgRx Effect

I'm using NgRx @Effect and for some effect I need to perform 2 API calls: the result of the first one is used in the second one and the I want to dispatch an Action with the 2nd API call as payload this way : @Effect() FetchDetails() { return…
Ghassen
  • 591
  • 1
  • 15
  • 33