Skip to content

Instantly share code, notes, and snippets.

@ronantreacy
Created October 30, 2018 09:25
Show Gist options
  • Save ronantreacy/f79e64d2ed147e660b3db9501bb2198d to your computer and use it in GitHub Desktop.
Save ronantreacy/f79e64d2ed147e660b3db9501bb2198d to your computer and use it in GitHub Desktop.
Comparison of Angular `Subject` and `BehaviorSubject`
var behaviorSubject = new Rx.BehaviorSubject(0);
var subject = new Rx.Subject();
subject.subscribe(v => {
console.log('SubjectObserver: ' + v)
});
behaviorSubject.subscribe(v => {
console.log('BehaviorSubjectObserver: ' + v)
});
behaviorSubject.next(1);
behaviorSubject.next(2);
subject.next(1);
subject.next(2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment