Angular 2 - Can't resolve all parameters for component: (?)

走远了吗. 提交于 2019-12-01 05:35:36

Make sure you have

"emitDecoratorMetadata": true,

in your tsconfig.js. You should not need to add @Inject() to your function parameters if that's enabled.

Import this

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

And change your constructor to

constructor(@Inject(AuthService) _authService: AuthService) 
{

}

you should @Inject any service into constructor before using it.

and your service should be injectable

@Injectable()
export class AuthService {

}

My problem ended up being nothing. I simply restarted the webpack watcher and then everything was fine. For reference, I'm using the Angular CLI.

The issue that raised this error for me was completely different. I had a logging category in the component that I had mistakenly used in the service, and thus the service had a dependency on the component and wasn't able to be created in time for it to be injected into the component.

TL;DR: Check the imports on the service that can't be injected.

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