Get angular 2 service inside a custom class instantiated by me

后端 未结 1 469
情歌与酒
情歌与酒 2021-01-17 04:12

Im building an angular 2 app, and i need a way to get a reference to a service/class that is injected/instantiated by angular framework.

I have a generic class...let

1条回答
  •  孤街浪徒
    2021-01-17 04:53

    As far as I know you have two choices:

    1) Manually pass the service into the Custom class constructor.

    let x = new Custom(this.userService);
    

    2) Make the Custom class a service as well. Then it will participate in Angular's DI.

    See this article for more information: https://blog.thoughtram.io/angular/2015/05/18/dependency-injection-in-angular-2.html

    0 讨论(0)
提交回复
热议问题