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.
Auf dieser Seite können Sie das Online-Video Behavior Subject - Component Communication using Observables mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer JsWiz 03 April 2017 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 43,082 Mal angesehen und es wurde von 243 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!