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
1
vote
1 answer

Angular - Integrate initial values and filters values in async pipe

I have this function that return an Observable's list of 'streets' by passing it city id: getStreetsByCityId(id: number) And it's the template:
  1. levi
    • 1,077
    • 2
    • 11
    • 24
1
vote
1 answer

Mergemap - More Than 2 Observables

I got a service method working that would get all of the items from a collection, and merge in user data from a different user collection so that it could easily be displayed on the front end. I tried to add a third layer of observables to pull and…
1
vote
3 answers

Should I use map or switchmap when using angular http module?

I use the following code in an angular app. I used the RxJS map call similar to how array map is used. After reading about RxJS switchmap operator, I'm not sure whether I should use map or switchmap. Should I use switchmap so the observable which is…
wonderful world
  • 10,969
  • 20
  • 97
  • 194
1
vote
2 answers

How to trigger an http request that has has a 401 error after the token has been refreshed?

I have the following problem: I make a request to an endpoint that validates if the token has expired. If it has expired, it returns a 401 error, I need the token to be refreshed at the time of the error (so far I am doing well). Once the token is…
Jeff
  • 35
  • 5
1
vote
1 answer

Return switchMap inner results in an array like forkJoin

I want to run a set of observables one after another, since each result depends on the previous. However, at the end I also need all the intermediate results, as they are given when we use forkJoin - in an array. I have the following code: …
1
vote
1 answer

switchmap complains not returning but thought i was

here is the error: ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. Here is the code publicresourceuploadtos3(event): Observable{ console.log('it got inside…
1
vote
1 answer

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,…
Nik Rubblers
  • 142
  • 1
  • 13
1
vote
1 answer

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…
Telly Ipock
  • 133
  • 3
  • 12
1
vote
1 answer

How to use check condition with in concatMap/switchMap in angular 7

I Am trying to download a pdf form API response. API-1 will return the file name, with the filename as input to the API - 2, I will download the pdf. It works well for positive cases. If incase there is no fileName returned from API - 1, I should…
FE-Deve
  • 13
  • 3
1
vote
1 answer

undefined when combine combineLatest and switchMap

I'm trying to combine two Observables to have few values for the call to service method that accepts two values. But here I have few errors Argument of type '([filter, sort]: [string, string]) => void' is not assignable to parameter of type…
1
vote
2 answers

How to subscribe to a chain of Observables that contains a Promise

I had a nested Observable situation, and after some research I found that it's best to use RxJS switchMap. For my case the first observable contains a Promise, so I have to await the first subscription result before it's passed to the second…
Berkenus
  • 23
  • 4
1
vote
1 answer

@ngrx/data How to cancel request providing with getAll, getWithQuery, getByKey

I use ngrx/data in my app. I have a very quick application. You can select something on UI and I need to update my view. A user can do it very quickly, I do not need any previous data from previous requests in that case. But when I add switchMap -…
1
vote
1 answer

Why switchMap does not require an observable when returning an simple array

I was originally searching how to return several actions in a ngrx effect, and found I need to return an array of actions. Then I noticed that returning a simple array in the switchMap works as fine as returning an observable created from this…
Vash42
  • 13
  • 2
1
vote
2 answers

switchMap is not canceling the previous request with below code

searchFunction is being called when a user enters value in autocomplete textbox. So, what this code should do is return the oprions to the autocomplete dropdown on the basis of user input and it should only show the options of the last query. If I…
Svibhor
  • 53
  • 10
1
vote
1 answer

Handling two HTTP requests (Angular + RxJS)

This is my first angular project, and I'm still not familiar that well with Observables and RxJS. In my project, at first I want to fetch all notifications with get request. After that, I want to take id of the last notification, so I could send…
user13067004
  • 131
  • 1
  • 1
  • 5