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
2
votes
1 answer

Operator switchMap() doesn't unsubscribe from the previous request

I created an Observable that emits text from edittext. Then in using the switchmap operator, I create a Single that looks for a match in the file. Here I subscribe: compositeDisposable.add(getEditTextObservable(editText) .debounce(500,…
pixwire
  • 116
  • 6
2
votes
3 answers

using switchMap to unsubscribe previous http request and only take latest one

I'm facing an issue currently, where a first search could take 5 seconds, and second one that takes 2 seconds, problem is, the first search which takes longer, will "erase" the results of the request that was done after, because the calls ends…
Dinosan0908
  • 1,082
  • 2
  • 8
  • 19
2
votes
1 answer

How to know if switchMap unsubscribed an inner Observable?

Since switchMap may cut off (unsubscribe) an inner Observable if a new item comes in, we expect the following: const items = from([1, 2]) const seen = [] const derived = items.pipe( switchMap(item => concat( of(`now:…
Dean Radcliffe
  • 2,194
  • 22
  • 29
2
votes
0 answers

Angular 6 & Rxjs 6 switchMap / how to pass first observable's result to another observable

I am having problem while using switchMap. What I am trying to do is: 1) Fetching first object/object's property from Firestore DB as an Observable 2) Using first Observable's property and make another Firestore call to get another Observable -which…
ilgaz
  • 61
  • 3
2
votes
1 answer

rxjs map operator not firing in pipe after switchMap

I thought myself pretty savvy when it came to rxjs, but I cannot figure out what I'm doing wrong. I'm trying to learn ngrx by converting my user login to an effect. My effect is firing correctly and the correct token response is returned (validated…
ye-olde-dev
  • 1,168
  • 2
  • 17
  • 29
2
votes
1 answer

How to cancel switchmap chain in RxJS?

The following use of switchMap... Rx.Observable.timer(0, 1000) // First switchMap .switchMap(i => { if (i % 2 === 0) { console.log(i, 'is even, continue'); return Rx.Observable.of(i); } console.log(i, 'is odd,…
marius
  • 1,533
  • 3
  • 16
  • 22
2
votes
2 answers

RxJS switchMap and different observables

New to Angular and RxJS, trying to understand this a bit... my app reacts to a UI event and that results in making a call out to a HTTP service that returns an Observable. I subscribe to it like so: this.myXYZService.search(query) .map(r => { //…
SBKDeveloper
  • 613
  • 1
  • 9
  • 20
2
votes
0 answers

Angular 2 Firebase Subscribe and switchmap multiple elements

I've Table "A" with an array inside that contain 0 to N key of table "B" my intent is to use swtich map for get all the record of table "B". until i've 1 to 1 key i've implement this simple function : ` // Combine Object let…
2
votes
2 answers

switchMap not accepting a function to be executed inside it

I have the following search that I try to execute: I want to search something based on the first id, this returns a FirebaseListObservable. I then try to execute code inside the switchMap function of the Observable because the search usually takes a…
Spurious
  • 1,903
  • 5
  • 27
  • 53
1
vote
2 answers

How do I replace subscrib in a subscribe in Angular RxJS?

I have a question about RxJS. I am creating a web app to manage the members of an association. I want to create a button to "reset" the database of a site. The steps are as follows: send an e-mail to all members to re-register Delete data Refresh…
Léandre
  • 45
  • 6
1
vote
1 answer

SwitchMap Angular

I'm using the angular material's table component, mat-table, along with pagination. I have the filter method that serves when the user types a text in the field to do a search, it is sent to the backend, the text, the size and the page. However, I…
1
vote
0 answers

RxJS keeping a source Observable alive if a switchMapped Observable emits an error

In the following example, the interval Observable will stop emitting values after the first throwError emits. const { interval, throwError, of } = Rx; const { take, switchMap, catchError } = RxOperators; interval(1000).pipe( switchMap(() =>…
Joe Bell
  • 11
  • 2
1
vote
1 answer

RxJs iif() operator is not subscribing to provided observable

With the following code I'm intending to subscribe to function1, and then depending on the result (saleAgreed), subscribe to a second observable; either function2 or of(undefined). See below: this.apiService.function1(id).pipe( …
Loz
  • 118
  • 11
1
vote
2 answers

How can I NOT wait for both observables to come and use data of 1 observable in swtichmap?

In this code below , I want student list to be rendered immediately and not wait for the second observable , but when second observable comes , it should check that student is not enrolled in all courses and then enable the button to add to…
Seth
  • 57
  • 10
1
vote
1 answer

RxJS: chain of calls with polling in the last switchMap

I have a very complicated example of chained RxJS calls with a lot of switchMap and etc. Everything is clear for me until I faced one requirement: I need to poll last request every 5 sec until response object contains a value. I stuck a bit... I…
brabertaser19
  • 5,678
  • 16
  • 78
  • 184
1 2
3
12 13