UPDATED 2.0. Stable: EventEmitter is now intended solely for linking components. This is best used for objects and ReplaySubjects. I updated the examples to 2.0 code.
BETA 1 IS UPDATED: You no longer need to call .toRx () on the emitter, so I update the code to match and add an example to cancel the subscription.
So, right now (Alpha 45) eventEmitter has a toRx () method that returns RxJS SUBJECT
You can do a little Google what it is and what you can do with it, but thatβs what you really mess with. When you call toRx (), it just returns an internal object from eventEmitter, so you can do this in your services constructor.
Then I added the function that you want to do translation for the event service
class EventService {
Then in your component you subscribe to the emitter
class ParentCmp { myData: any; constructor(private evt: EventService) {
And here is an extended class with built-in unsubscribe (dispose)
export class ParentCmp implements OnDestroy { myData: any; subscription: any; constructor(evt: EventService) {
I am a bit confused about your last question, but Iβll think about the term βget a message.β You must be listening to something that the subscription method does and is required.
The cool thing is that now you can call it observable everywhere (even in other services), and IMO is the best way to communicate between components. They do not need to know their position in the tree or to care about whether other components exist or are listening.
I hid my Plunker while working HERE (still on Alpha45)
RxJs source and related information
Angular2 source and object information inside eventEmitter
Dennis smolek
source share