Angular service call function in component
问题 So I know you can have two unrelated components communicate with each other via a service by having one component emit an event in the service and the other subscribe to it in the service. My question: Can a service call a function in a component directly? 回答1: Not by default. A service is an instance of a class, nothing more. @Injectable() class MyService { } @Component({ selector: 'my-component', ... )} class MyComponent { constructor(private myService:MyService) {} } @NgModule({ providers: