Questions tagged switchmap

Explore the latest questions and answers asked by our top developers.

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 this.actions.pipe( ofType(actions.SOME_ACTION), switchMap((action: SomeAction) => this.myService.getContext()), […]

By Ghassen
Published
Categorized as angular, ngrx, ngrx-effects, redux, switchmap Tagged , , , ,

How to use Angular async pipe with switchMap observable?

I have a simple Angular app that retrieves a list of weathers from back-end api and displays them. The particular thing is, that the url of back-end api comes from another observable, because of that I use switchMap operator to retrieve the list of weathers. Here is a simple code I wrote to demonstrate the […]

angular how to get array of nested object from two tables one-to-many related

Hi everybody I have 2 mysql tables: itemsClass which contains a list of possible classes, and itemType which refers to itemClass and contains type values of a particular class. I’m trying to build a service which returns an Observable<Item[]>, combining two http.get Observables, suiting this interface: interface Item{ itemcClassId:any; //class.id itemClassName:any; //class.name itemTypeValue?:any; //if the […]

Angular Unit Testing with RxJS, pipe, and subscribe

I’m trying to write some unit test (Jasmine) for my Angular 11 Component. In ngOnInit() it calls two http ajax functions from the service that return data from the database. Both return a Subscription (rxjs), and I chained them with pipe() and switchMap(). It’s something like this: ngOnInit(): void { const configID = 12345; this.service.getDataOne(configID) […]

By Telly Ipock
Published
Categorized as angular, jasmine, rxjs, switchmap, unit-testing Tagged , , , ,

RXJS, combine different operations on the same observable at the same component

the thing is that i have something like this. In this code i’m subscribing two times at the same observable and this is a problem, because i have redundant access to first switchMap when second subscribe is called, so i want to make all with one subscription but i can’t see how to do it. […]

By Sfrag
Published
Categorized as angular, observable, rxjs, switchmap Tagged , , ,

add values to 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 executing if I return tInfo from map it gives following error […]

By Gaurav Matta
Published
Categorized as angular, arrays, observable, switchmap Tagged , , ,

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 executing if I return tInfo from map, it gives following error […]

By Gaurav Matta
Published
Categorized as angular, arrays, observable, rxjs, switchmap Tagged , , , ,

Why does my http request cancel/stop observables stream?

I have an array of ‘applications’ and I want each application to have new property called Blobs. I have to make new http request to get Blobs for every single application and I use switchmaps for that. However, for some reason it only emits the last application and not every single one. ( bad explanation […]

By Vazhaabdu
Published
Categorized as angular, rxjs, switchmap, typescript Tagged , , ,

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(): Observable<MyData> { const url = `${this.context}/search`; return this.http.get<MyData>(url) .pipe( switchMap((myData: MyData) => […]

By Sunil Garg
Published
Categorized as angular, rxjs, switchmap Tagged , ,

Swicthmap in rxjs doesnt cancel the previous request

i am basically calling an api on keyup event of a textbox using switchmap. Problem that I am facing is that switchmap doesnt cancel the previous ongoing api call when a new api call is made import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from ‘@angular/core’; import {fromEvent, Observable} from "rxjs"; import {debounceTime, distinctUntilChanged, map, switchMap} from […]

By Slow Death
Published
Categorized as angular, javascript, rxjs, rxjs5, switchmap Tagged , , , ,
1 2 3 4

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq