- RxJS Tutorial
- RxJS - Home
- RxJS - Overview
- RxJS - Environment Setup
- RxJS - Latest Updates
- RxJS - Observables
- RxJS - Operators
- RxJS - Working with Subscription
- RxJS - Working with Subjects
- RxJS - Working with Scheduler
- RxJS - Working with RxJS & Angular
- RxJS - Working with RxJS & ReactJS
- RxJS Useful Resources
- RxJS - Quick Guide
- RxJS - Useful Resources
- RxJS - Discussion
RxJS - Transformation Operator switchMap
In the case of switchMap operator, a project function is applied on each source value and the output of it is merged with the output Observable, and the value given is the most recent projected Observable.
Syntax
switchMap(project_func: function): Observable
Parameters
project_func − It takes in project_func as the argument which is applied to all the values emitted from source observable and returns an Observable.
Return value
The return value is an Observable, that has values based on the project_func applied on each value of source observable.
Example
import { of} from 'rxjs'; import { switchMap } from 'rxjs/operators'; let text = of('Welcome To'); let case1 = text.pipe(switchMap((value) => of(value + ' Tutorialspoint!'))); case1.subscribe((value) => {console.log(value);});
Output
Advertisements