Angular’s reactive world revolves around Subjects, but the star is often the BehaviorSubject — why? Because it always starts with a value, and when you subscribe, you immediately get the latest emission (like receiving the current issue of a magazine). Meanwhile, ReplaySubject lets you go further by replaying multiple past values (no default), and a plain Subject is just “live only” — no past, no future. Let’s dig into when and why to use each.
Alain Chautard
October 8, 2025
The most common type of Subject used with Angular is BehaviorSubject
. Why is that? Because a BehaviorSubject
has two exciting features that a plain Subject
does not have:
Imagine subscribing to a magazine and receiving its latest published issue immediately. That’s what a BehaviorSubject
does. This is helpful if you have components that need to know about the app’s current user. When the component subscribes to the “current user,” we want to get that info immediately and not wait for the next user update.
Also, since behavior subjects always have a value, they have a getValue(
) method that synchronously returns the current value.
A ReplaySubject
is very similar to a BehaviorSubject
, with two key differences:
The constructor parameter determines how many values should be replayed to new subscribers:
A plain Subject
has none of the above capabilities. When a value is emitted, current subscribers receive it, but future subscribers won’t. There is no replaying of the latest value(s), which makes plain Subjects less interesting to work with.
Get the latest news and updates on developer certifications. Content is updated regularly, so please make sure to bookmark this page or sign up to get the latest content directly in your inbox.
Subject, BehaviorSubject, and ReplaySubject
Angular’s reactive world revolves around Subjects, but the star is often the BehaviorSubject — why? Because it always starts with a value, and when you subscribe, you immediately get the latest emission (like receiving the current issue of a magazine). Meanwhile, ReplaySubject lets you go further by replaying multiple past values (no default), and a plain Subject is just “live only” — no past, no future. Let’s dig into when and why to use each.
Alain Chautard
Oct 8, 2025
Unravel the mystery of JavaScript's event bubbling and take control of your event handling
Ever clicked a button and had unexpected things happen to its parent elements? You might have just witnessed the magic (or mischief!) of JavaScript's event bubbling. It's a core concept that, once understood, will save you headaches and help you debug event-related issues.
Martin Ferret
Oct 8, 2025
Serverless functions in Nuxt: backend power without a backend
Serverless functions are tiny pieces of code that run on demand in the cloud. You don’t provision servers or infrastructure, or write scaling rules. Cloud providers handle the underlying infrastructure, automatically scaling resources based on demand. They’re perfect for lightweight APIs, form handlers, webhooks, simple auth endpoints, and glue code.
Reza Baar
Oct 8, 2025
We can help you recruit Certified Developers for your organization or project. The team has helped many customers employ suitable resources from a pool of 100s of qualified Developers.
Let us help you get the resources you need.