Angular 2:检测从哪个组件服务调用

时间:2017-03-22 11:06:59

标签: angular

我有 MyService ,它被注入 ComponetA ComponetB

是否有可能找出哪个组件是 MyService.myMethod()

@Injectable()
export class MyService {

  public myMethod(): void {
    console.log('called from component: ' + component);
  }
}

1 个答案:

答案 0 :(得分:2)

只有解决方案是使用一个传递给被调用函数的参数。

编辑:之前提及here的建议不起作用,因为它只能在没有严格模式的情况下运作。

相关问题