Reputation:
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
Upvotes: 0
Views: 452
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