BehaviorSubject

Is very similar to Subject, except that it has one big feature that Subject doesn’t have. The ability for subscribers that come in later in the flow to still get some of the previous data.

Looking to the previous image, imagine that the component on the right subscribes and we get number 1. Now if the component on the left were to subscribe, they’re not going to get number 1 or 2 because it’s already been passed and the component at the left doesn’t have the information. The main point here is that the last value that was emitted can still be retrieved by someone who subscribes later on the flow. For example, we’ve already talked about 1 and 2 have been sent to the component on the right, but if the one on the left now subscribes, they’re going to get the last value that was emitted. So, that would be the number 2. Then they’ll get any future values as you can see at the previous image. The big difference between Subject and BehaviorSubject is that with Subject you only get data after you subscribe and you don’t get any of the previous data. With BehaviorSubject you can get the last value that was sent out, even if you subscribe 10 minutes later.