- 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 - Creation Operator iif
This operator will decide which Observable will be subscribed.
Syntax
iif(condition: Function):Observable
Parameters
condition − The condition is a function if its return true the observable will be subscribed.
Return value
An observable will be returned based on the condition.
Example
import { iif, of } from 'rxjs'; import { mergeMap, first, last } from 'rxjs/operators'; let task1 = iif( () => (Math.random() + 1) % 2 === 0, of("Even Case"), of("Odd Case") ); task1.subscribe(value => console.log(value));
iff() operator acts like a ternary operator and mostly used for if-else condition cases.
Output
Odd Case
Advertisements