what is diff in @Injectable() and @Inject

僤鯓⒐⒋嵵緔 提交于 2021-02-09 09:01:13

问题


I am working on angular2 I have created service and inject those service using @Inject in component. I am confuse with the use of @Injectable() in service itself and what diff it makes.


回答1:


@Inject() is a manual mechanism for letting Angular 2 know that a parameter needs to be injected

@Injectable() lets Angular 2 know that a class can be used with the dependency injector. @Injectable() is not strictly required if the class has other Angular 2 decorators on it. What is important is that any class that is going to be injected with Angular 2 is decorated.

However best practice is to decorate injectables with @Injectable(), as it is makes more sense to the reader.



来源:https://stackoverflow.com/questions/37939978/what-is-diff-in-injectable-and-inject

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