问题
Why Event Emitter can't use in service in angular 6?
In Angular documentation they mentioned, "Use in directives and components to emit custom events"
回答1:
Because in services all waht you have to do is manipulating data, if you want to notify the data changes you can use Subjet
or BehaviorSubjet
. EventEmitter is generally used to notify changes from child to parent and as said is supposed to be used only for @Output
.
please take a look at this link
来源:https://stackoverflow.com/questions/52109509/use-of-eventemitter-in-service-of-angular6