Get angular 2 service inside a custom class instantiated by me

拟墨画扇 提交于 2019-12-01 14:55:17

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!