0

I set up a new Angular 5 project and it seems @Injectable decorator doesn't work. I have to inject manually with @Inject decorator for each parameter of constructors. I'm using Angular 5.0.5 with TS 2.4.2. This is my tsconfig.json:

{ "compileOnSave": false, "compilerOptions": { "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es5", "typeRoots": [ "node_modules/@types" ], "lib": [ "es2017", "dom" ] } }

I lost a lot of time on it and i really don't understand what happens. Do you have an idea of the problem ?

2 Answers2

0

My guess is that you are maybe trying to inject an interface:

constructor(someDependency: SomeInterface) { /* ... */ }

The @inject decorator will be required.

If you are trying to inject a class:

constructor(someDependency: SomeClass) { /* ... */ }

The @injectable annotation should be enough.

Learn more at Is it possible to inject interface with angular2?

If this is not your problem maybe there is something wrong with your project. Maybe you are importing the "reflect-metadata" module more than once?

Remo H. Jansen
  • 23,172
  • 11
  • 70
  • 93
0

My bad, i just found the problem... I commented the 'core-js/es7/reflect' import in my polyfill.js.

Thanks to you