- 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 - Conditional Operator defaultIfEmpty
This operator will return a default value if the source observable is empty.
Syntax
defaultIfEmpty(defaultValue = null): Observable
Parameters
defaultValue − The argument defaultValue can be given some value or if not given it is null by default.
Return value
It will return an observable with a default value if the source observable is empty.
Example
import { of } from 'rxjs'; import { defaultIfEmpty } from 'rxjs/operators'; let list1 = of(); let final_val = list1.pipe(defaultIfEmpty('Empty! No values')); final_val.subscribe(x => console.log(x));
Output
Empty! No values
Advertisements