RxJS - Filtering Operator ignoreElements



This operator will ignore all the values from the source Observable and only execute calls to complete or error callback functions.

Syntax

ignoreElements()

Return value

It returns an observable that will call complete or error based on the source observable.

Example

import { of } from 'rxjs';
import { ignoreElements } from 'rxjs/operators';

let all_nums = of(1, 6, 5, 10, 9, 20, 40);
let final_val = all_nums.pipe(ignoreElements());
final_val.subscribe(
   x => console.log("The last value is = "+x),
   e => console.log('error:', e),
   () => console.log('The task is complete')
);

ignoreElements() operator will directly execute the complete method if success and error if failure and ignore everything else.

Output

ignoreElements Operator
Advertisements