I\'ve been using the Heroes tutorial in the Angular 2 docs to experiment. However, I\'ve come to a point that I don\'t understand what\'s happening with this error:
In my case, I fix this problem using @Inject
decorator. Try this:
import {Inject} from '@angular/core'
constructor(@Inject(HeroService) private _heroService: HeroService,
@Inject(RouteParams) private _routeParams: RouteParams) {}
My project is configured with JSPM and this is the only way to work with dependency injection, I do not why, anyone has an explanation?
Edited: I have found the solution. In my case, I have to add this configuration into config.js file
System.config({
baseURL: "",
defaultJSExtensions: true,
transpiler: "typescript",
typescriptOptions: {
"target": "es5",
"emitDecoratorMetadata": true
},
paths: {
"npm:*": "jspm_packages/npm/*",
....
Now I can remove @Inject decorator and this sentence works properly
constructor(private _heroService: HeroService,
private _routeParams: RouteParams) {}
The key is emitDecoratorMetadata: true