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

Angular getting Authorization token asynchronously before HTTP calls

before posting this i went to many other similar questions and not able to find solutions. like Angular 2 - Inject authorization token before each Http request I am using AWS session which provides me Authorization token for makeing HTTP request.…
gaurang171
  • 9,032
  • 4
  • 28
  • 30
0
votes
1 answer

Flattening nested observables and include regular variables in outer observable

Sorry to clarify, the following data structure: const obs = Observable.fromPromise(firebase.storage().ref('Test').child('logo.png').getDownloadURL()); const json = { obs: obs, test: 1 }; const obs2 = Observable.of( json ); So that would…
smeddles24
  • 101
  • 1
  • 1
  • 8
0
votes
1 answer

Error implementing .switchMap in Angular project

I'm am learning firebase to implement with my angular projects but running in to a issue with the .switchMap() operator. My understanding is that it is supposed to get one observable and switch to another. I am trying to get firebase user and…
0
votes
1 answer

RxJs switchMap: wow to pass multiple values?

At https://www.learnrxjs.io/recipes/smartcounter.html I found a great example of an numbercounter in Angular 2+, the code looks likes: @Component({ selector: 'number-tracker', template: `

{{ currentNumber }}

` }) export class…
Johan Walhout
  • 1,446
  • 3
  • 22
  • 38
0
votes
2 answers

Trying to cancel existing http request with new one using switchMap in Ionic 3

My goal is to use RxJs switchMap in an Ionic 3 project, to cancel any ongoing login attempts if a server is offline, and use latest request only. Otherwise I can get some unwanted asynchronous side effects later. In my view layer, I'm using…
JGFMK
  • 8,425
  • 4
  • 58
  • 92
0
votes
0 answers

Angular2 : 404 response using activatedRoute and switchmap

Method for fetching the selected users details inside service is : 'getSelectedUser(name)', which uses an Observable and in the required component we are calling that service and applying switchMap and then subscribing to it. But somehow it's not…
0
votes
1 answer

BehaviorSubject from switchMap then getValue is not a function error

this is my class ts code this.product$ = >this.route.params.switchMap( (params): BehaviorSubject => this.productService.getProduct(params['_id']) ); this is code from service getProduct(_id: string):…
Aladdin Mhemed
  • 3,817
  • 9
  • 41
  • 56
-1
votes
2 answers

Modify Observable array before subscribing by rxjs operators

Having two models look like this: export class Game { id: number; name: string; platform: number; } export class Platform { id: number; name: string; } having an observable array of the Game object that has a property of platformId which is…
FarbodKain
  • 229
  • 3
  • 15
-1
votes
1 answer

Angular switchMap sending undefined data to service

I have two observable called: callbacks and system. I want to merge some data, so in my callback I have the property "systemId" and in my system I have the the property…
Desenv Junior
  • 101
  • 1
  • 1
  • 10
-1
votes
2 answers

Cannot get result of first HTTP request using RxJS' switchMap

I am trying to make 2 HTTP requests and in the first call I try to create a record and then according to its results (response from the API method) I want to execute or omit the second call that updates another data. However, although I can catch…
Prag Dopravy
  • 201
  • 1
  • 3
  • 12
-1
votes
1 answer

RxJS: Extracting an array of values from complex json via http

Angular 10 (Simplified) I have an http get that returns a country and a list of States in the country: {"id":1, "countryMeta": {"statesList": [ {"name":"AB","value":"AB"}, …
Ian Vink
  • 66,960
  • 104
  • 341
  • 555
-1
votes
1 answer

Second subscription doesn't start upon switchMap from the first one in RXJS

I have this working code. It fetches the ID from the router and applies it as a parameter to get load in the data for the component. this.route.params.subscribe(_ => { this.id = _.id; this.service.getMineral(this.id) .subscribe(suc =>…
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
-1
votes
1 answer

why i can't use switchMap inside observable

I wrote this function, import { Alert } from './../classes/alert'; import { AlertService } from './alert.service'; import { AlertType } from './../enums/alert-type.enum'; import { Injectable } from '@angular/core'; import { Router } from…
Hasitha Chandula
  • 425
  • 4
  • 12
-2
votes
1 answer

Property 'switchMap' does not exist on type 'Observable'

In my angular 13 app I am using "rxjs": "^7.5.2". I am using switchMap from 'rxjs/operators', I am getting an error saying Property 'switchMap' does not exist on type 'Observable' when I do an ng build. How can I resolve this, any clue Here is the…
user1015388
  • 1,283
  • 4
  • 25
  • 45
-2
votes
3 answers

SOLVED - When running 2 observables one after another - getting result based on the first one

I have 2 functions that return Observables that I would like to execute one after another. function1 return Observable and function2 return type Observable I want that the function that execute them return boolean based of…
Guy E
  • 1,775
  • 2
  • 27
  • 55
1 2 3
12
13