[英]Angular 5: cannot get dependency injection working
我有一個角度5(“ @ angular / core”:“ 5.1.2”)應用,但我不斷收到此錯誤
未捕獲的錯誤:無法解析FooComponent的所有參數:(?)。
服務:
@Injectable()
export class FooService { }
零件:
@Component({template: '<p></p>'})
export class FooComponent {
constructor(private s: FooService) { }
}
模塊:
@NgModule({
declarations: [ AppComponent, FooComponent ],
bootstrap:[ AppComponent ],
providers: [ FooService ] })
export class AppModule {}
我的tsconfig:
{
"compilerOptions": {
"baseUrl": "",
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"lib": [
"es6",
"dom"
],
"mapRoot": "./",
"module": "commonjs",
"moduleResolution": "node",
"rootDir": "./app",
"outDir": "../dist",
"sourceMap": true,
"target": "es5",
"noEmitOnError": true,
"typeRoots": [
"./node_modules/@types"
]
},
"include": [
"./**/*.ts"
]
}
知道我缺少什么嗎? 請注意,我使用的是es6
lib, @Injectable
沒有任何參數。 我似乎找不到很多好的例子。
通常我們如何在角度上調試DI?
@Component({
template: '<p></p>'
})
export class FooComponent {
constructor(@Inject("FooService") private s: FooService) { }
}
錯過了@Inject
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.