DEV Community

Cover image for Behaviour Subject In Angular (rxjs)
Shaik Shahbaaz Alam
Shaik Shahbaaz Alam

Posted on

Behaviour Subject In Angular (rxjs)

Behaviour Subject is one of the useful features in rxjs which comes pre installed in angular 9+

What is a Subject?

A RxJS Subject is a special type of Observable that allows values to be multicasted(means one observable can be used by multiple / all components) to many Observers. While plain Observables are unicast (each subscribed Observer owns an independent execution of the Observable), Subjects are multicast.

How to use?

Creating the subject

And then utilize this observable in other components.

Utilizing the subject

Use:

  • To use any data in different components and just store it once and use everywhere in the angular project. Drawback:
  • This sometimes gives old, unexpected values when used with APIs. So, when working with API's we can use AsyncSubject.

Top comments (0)