Master Angular by example - https://goo.gl/97onLe
Mini project and example of how to send data between unrelated components using the RxJS behavior subject observable. Head to 12:43 to see the start of actual implementation.
Repo: https://github.com/jakblak/angular_Ex...
Check the branches
Link to Stackoverflow question: http://stackoverflow.com/questions/34...
Link to RxJS docs on behavior subject: http://reactivex.io/rxjs/manual/overv...
The original question asked whether to use EventEmitter or Observable as a way to perform delegation.
This example is an alternative to using Event Emitter and is suggested as a better alternative.
A Subject is both an Observable (so we can subscribe() to it) and an Observer (so we can call next() on it to emit a new value). We exploit this feature. A Subject allows values to be multicast to many Observers. We don't exploit this feature (we only have one Observer).
BehaviorSubject is a variant of Subject. It has the notion of "the current value". We exploit this: whenever we create an ObservingComponent, it gets the current navigation item value from the BehaviorSubject automatically.
On this page of the site you can watch the video online Behavior Subject - Component Communication using Observables with a duration of hours minute second in good quality, which was uploaded by the user JsWiz 03 April 2017, share the link with friends and acquaintances, this video has already been watched 43,082 times on youtube and it was liked by 243 viewers. Enjoy your viewing!