问题
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