Member-only story
When To Use RxJS Subject, BehaviourSubject, ReplaySubject, AsyncSubject, or Void Subject in Angular
The power is in the details
Angular has many types of Observables which you can use. Maybe you’ve seen Subject, BehaviourSubject
, ReplaySubject
, or AsyncSubject
in Angular examples and wondering what they are and when you can use them.
In this post, I want to dive deeper into what those types of Subjects are and when you should use them. So buckle up and enjoy the ride.
What is a Subject?
RxJS is responsible for the reactivity in Angular. A Subject is a particular type of Observable from the RxJS library.
If you don’t know what an Observable is, check this post by “Understanding RxJS Observables and why you need them” on the LogRocket blog.
Unicast
An Observable is unicast. An Observer and its Subscriber have a one-to-one relationship. Each subscribed Observer owns an independent execution of the Observable.