3

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.

Rhushikesh
  • 3,630
  • 8
  • 45
  • 82
  • Learn more here:[Dependency Injection in Angular 2](http://blog.thoughtram.io/angular/2015/05/18/dependency-injection-in-angular-2.html) and in [official docs](https://angular.io/docs/ts/latest/guide/dependency-injection.html) – Sasxa Jun 21 '16 at 09:13

1 Answers1

5

@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.

null canvas
  • 10,201
  • 2
  • 15
  • 18