Lesson
What is the difference between a BehaviorSubject and a regular Subject?
Both BehaviorSubject and Subject are a type of Observable that we can use to stream data throughout our application.
- Duration
- 1 min
- Access
- Free
- Transcript
- Needs source
Both BehaviorSubject and Subject are a type of Observable that we can use to stream data throughout our application.
The main difference, is that the BehaviorSubject has an initial value, and when you subscribe to it, it will give you
the last value it emitted.
myBehaviosSubject$ = new BehaviorSubject<string>('I have an initial value');
myRegularSubject$ = new Subject<string>();
}The regular Subject doesn't have an initial value, and even if it has been emitting data, when you subscribe to it you won't get any data until it emits something again.