Angular 2: discovery from which the component service is called

I have a MyService that gets injected into Component and Component .

Is it possible to find out from which component MyService.myMethod () is called ?

@Injectable()
export class MyService {

  public myMethod(): void {
    console.log('called from component: ' + component);
  }
}
+4
source share
1 answer

The only solution is to use a parameter that will be passed to the called function.

EDIT: The previous suggestion for the link will not work here because it only works in strict mode.

+2
source

Source: https://habr.com/ru/post/1672910/


All Articles