Home » RxJS iif() Creation Operator

RxJS iif() Creation Operator

by Online Tutorials Library

RxJS iif() Creation Operator

RxJS iif() operator is a creation operator used to decide which observable will be subscribed at subscription time.

In other words, we can say that the RxJS iif() operator facilitates you to subscribe to the first or second observable according to the condition.

Syntax:

Following is the syntax of the RxJS iif() creation operator:

Or

Or

Parameter Explanation

  • condition: It specifies a condition that which observable should be chosen. If it returns true then the observable will be subscribed.
  • trueResult: It is an optional argument. Its default value is EMPTY. Type: SubscribableOrPromise.
  • falseResult: It is also an optional argument. Its default value is EMPTY. Type: SubscribableOrPromise.

Return value

The RxJS iif() operator returns either the first or second observable, depending on the condition.

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

Example 1 (Simple iif)

Output:

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

RxJS iif() Creation Operator

Example 2 (iif with default)

Output:

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

RxJS iif() Creation Operator


Next TopicRxJS Operators

You may also like