Behavior Subject - Component Communication using Observables

Опубликовано: 03 Апрель 2017
на канале: JsWiz
43,082
243

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.


На этой странице сайта вы можете посмотреть видео онлайн Behavior Subject - Component Communication using Observables длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь JsWiz 03 Апрель 2017, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 43,082 раз и оно понравилось 243 зрителям. Приятного просмотра!