Subject and BehaviorSubject

A Subject is an Observable that can also be fed manually with next(): it broadcasts each value to all its subscribers. A BehaviorSubject additionally keeps the last value and supplies it immediately to any new subscriber, which makes it a common vehicle for shared state.

Example

const user$ = new BehaviorSubject<User | null>(null)
user$.next(utilisateur)

Related concepts

The whole glossary