Home » RxJS publishBehaviour() Multicasting Operator

RxJS publishBehaviour() Multicasting Operator

by Online Tutorials Library

RxJS publishBehaviour() Multicasting Operator

RxJS publishBehaviour() operator is a multicasting operator that returns a ConnectableObservable by using the BehaviourSubject. Here, the connect() method has to be used to subscribe to the observable created.

In other words, we can say that the RxJS publishBehaviour() operator returns ConnectableObservable and requires to use connect() method to subscribe to the observables.

Syntax:

Following is the syntax of the RxJS publishBehaviour() multicasting operator:

Or

Parameter Explanation

There is no such parameter that we have to explain.

Return value

The RxJS publishBehaviour() operator returns a ConnectableObservable that causes the source observable to emit items to its observers when the connection is established.

Let us see an example of the RxJS publishBehaviour() operator to understand it clearly.

Example

Output:

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

RxJS publishBehaviour() Multicasting Operator

In the above example, you can see that the default value is displayed first, and later the values from the observable are displayed according to the setting in the example.


Next TopicRxJS Operators

You may also like