Home » RxJS ignoreElements() Filtering Operator

RxJS ignoreElements() Filtering Operator

by Online Tutorials Library

RxJS ignoreElements() Filtering Operator

RxJS ignoreElements() operator is a filtering operator that ignores all the values from the source Observable and only execute calls to complete or error callback functions.

In other words, you can say that the RxJS ignoreElements() operator suppresses all of the items emitted by the source Observable but allows its termination notification (either onError or onCompleted) to pass through unchanged.

You should only apply the ignoreElements() operator to the Observable only if you do not care about the items being emitted by an Observable, but you want a notification when it completes or terminates with an error.

Syntax:

Following is the syntax of the RxJS ignoreElements() operator:

Or

Parameter Explanation

There are no parameters to explain.

Return value

OperatorFunction<any, never>: The RxJS ignoreElements() operator’s return value is an empty observable that only calls complete or error, according to which one is called by the source Observable.

Let us see some examples of the RxJS ignoreElements() operator to understand it clearly.

Example 1 (Ignore all elements from source)

Output:

After executing the above example, you will see the following result:

RxJS ignoreElements() Filtering Operator

Example 2

Output:

After executing the above example, you will see the following result:

RxJS ignoreElements() Filtering Operator

Example 3 (Display errors only)

Output:

After executing the above example, you will see the following result:

RxJS ignoreElements() Filtering Operator

In the above example, you can see that it has shown only the error message.


Next TopicRxJS Operators

You may also like