Behavior Subject - Component Communication using Observables

Pubblicato il: 03 aprile 2017
sul canale di: 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.


In questa pagina del sito puoi guardare il video online Behavior Subject - Component Communication using Observables della durata di ore minuti seconda in buona qualità , che l'utente ha caricato JsWiz 03 aprile 2017, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 43,082 volte e gli è piaciuto 243 spettatori. Buona visione!