user3945261
user3945261

Reputation:

Angular 2 eventEmitter not work

All did well as in the manual, here's the code:
WebSocketBroadcaster

import {EventEmitter, Injectable} from "@angular/core";

@Injectable()
export class WebSocketBroadcaster {
    ee: EventEmitter<any> = new EventEmitter<any>();
}

WebSocketService code

bootstrap

bootstrap(AppComponent, [
    appRouterProviders,
    disableDeprecatedForms(),
    provideForms(),
    WebSocketBroadcaster
])

client component code

console.log(data) in client.component does not work
console.log(this.broadcaster.ee); output output

Upvotes: 0

Views: 452

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657018

EventEmitter are not supposed to be used in services. EventEmitter is only for @Output() properties in components.

In services use Observable and Subject instead.

Upvotes: 3

Related Questions