Angular 2 Di not working - cannot resolve all parameters for

烂漫一生 提交于 2019-12-01 02:28:34

Update

After update in question OP is using Typescript already, I'd suggest you to add emitDecoratorMetadata: true inside your tsconfig.json. It is necessary so the JavaScript output creates the metadata for the decorators inside a transpiled script file.


You need to Add @Inject to create an instance of CourseService inside AppComponent

constructor(@Inject(CourseService) courseService: CourseService) {
}

In a case if you are using typescript, you don't need to have @Inject decorator there in place. Typescript done that for you.

I was able to solve this problem by adding:

import {Inject} from '@angular/core';

in the component and annotating the service to be injected with:

constructor(@Inject(CourseService) courseService: CourseService) {

In my case the issue was caused by @angular/forms . If you are using it near the faulty component start checking your @angular/forms and find a fix around it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!