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.
Following is the syntax of the RxJS publishBehaviour() multicasting operator:
There is no such parameter that we have to explain.
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.
After executing the above example, you will see the following result:
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.