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
2 answers

Array of inner subscriptions with rxjs

I'm trying to improve the flattening and reduce the chaining inside my Rxjs code. A REST call of my service getAllItems() returns the following Items[]: [{ id: 101, name: 'Car', owner: 1 }, { id: 102, name: 'Table', owner: 2 }] I have…
Victor Martinez Calvo
  • 1,717
  • 1
  • 12
  • 11
0
votes
1 answer

update observable object from array in observable object

I have documents id in the Information I am getting from service. I need documents Info to be attached to this parent information and return parent. Not able to return observables in loop. The second switch map is working fine. The first is not…
0
votes
1 answer

Invalid argument type when returning object from Rxjs switchmap

In angular I have created a service that gets the data from different service and merge the data with the first service. If the first service returns empty data then i dont need to call the second service. Here is the code searchData():…
Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
0
votes
1 answer

Swicthmap in rxjs doesnt cancel the previous request

I am basically calling an API on keyup event of a textbox using switchmap. The problem that I am facing is that switchmap doesn't cancel the previous ongoing API call when a new API call is made import {AfterViewInit, Component, ElementRef, OnInit,…
Slow Death
  • 31
  • 3
0
votes
2 answers

Why does forkJoin not complete for an array of new Observables?

I'm trying to use forkjoin on some asynchronous tasks but for some reason I don't get the emission on forkjoin. See stackblitz https://stackblitz.com/edit/angular-12-form-validation-yrstmk?devtoolsheight=33&file=src/app/app.component.ts import {…
Austen Stone
  • 948
  • 1
  • 10
  • 21
0
votes
3 answers

Can you transform the result of switchMap observable to get its value and not the observable itself?

I'm trying to create an in-memory singleton that holds the current vendor a person is browsing on. A guard is used on all specific routes to catch the parameter: canActivate( route: ActivatedRouteSnapshot, state: RouterStateSnapshot):…
Jnr
  • 1,504
  • 2
  • 21
  • 36
0
votes
0 answers

switchMap only cancelling some endpoints

I have a form control input to search for results. component.html I'm using valueChanges observable to check for changes. component.ts this.xx = this.input.valueChanges.pipe( switchMap(res => { return…
F.H.
  • 1,456
  • 1
  • 20
  • 34
0
votes
1 answer

Angular Reactive Forms - Call API on change event

I have a component that contains a table with exercise data and one input to search by name. The following code works perfectly. searchTerm: FormControl; searchTerms$: Observable; exercises$: Observable; constructor( private…
0
votes
2 answers

Combine multiple Firestore database collection calls results in a single array

After successfully getting all references for a sub-collection that i'm using for subsequent db calls i'm trying to combine results in a single array of Observables. Right now the value inside subscription of the loadAllLessons() function updates to…
ISS
  • 406
  • 6
  • 24
0
votes
1 answer

Repeating the emission of a Subject

I'm not getting why the following BehaviourSeubject is not emitting three times const numbers = [1, 2, 3, 4] const urls$ = new BehaviorSubject(numbers) urls$.pipe(repeat(3)).subscribe(console.log) Also, what is the semantic of the…
Antonio Santoro
  • 827
  • 1
  • 11
  • 29
0
votes
0 answers

peculiar behavior of rxjs SwitchMap while calling an HTTP Service

I have rxjs SwitchMap which calls an HTTP service that returns an HTTP observable. But the switchmap hits only the first time or until the first result retrieved. after that it does not execute no matter how much I push in behavior or replay…
0
votes
2 answers

Api typeahead search using RxJs switchMap sending too many requests (angular)

I'm currently building a type ahead search. I'm trying to adapt it from the example here https://www.learnrxjs.io/learn-rxjs/recipes/type-ahead but I need to make an http call on keystroke. I'm testing it against timezones from my api. It works, but…
Goht
  • 46
  • 7
0
votes
1 answer

Angular only run forkJoin if response is not empty?

I have a function for getting a list of notification rules. The problem is if no notification rule already exists then the function crashes. The line causing the issue is response.rules.model.map((rule) => { returns the error: ERROR TypeError:…
user123456789
  • 1,914
  • 7
  • 44
  • 100
0
votes
1 answer

switchMap not working with string observable

switchMap not working with string observable. If I use it inside a function then call the function, it won't work Below is the stackblitz link to code: https://stackblitz.com/edit/typescript-btkudb?file=index.ts
Svibhor
  • 53
  • 10
0
votes
1 answer

forkJoin depending on another response in Angular

I have a switchMap and then a forkJoin but one of these calls depends on another one this.route.paramMap .pipe( switchMap((params) => { let id = parseInt(params.get('id')); return forkJoin({ …
Atlas91
  • 5,754
  • 17
  • 69
  • 141