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

前端 未结 4 622
死守一世寂寞
死守一世寂寞 2021-01-12 06:47

I started an Angular2 app and I have an issue since days !

Can\'t resolve all parameters for HomeComponent: (?).(…) 

But my issue is not a

相关标签:
4条回答
  • 2021-01-12 07:09

    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.

    0 讨论(0)
  • 2021-01-12 07:12

    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.

    0 讨论(0)
  • 2021-01-12 07:23

    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 {
    
    }
    
    0 讨论(0)
  • 2021-01-12 07:29

    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.

    0 讨论(0)
提交回复
热议问题