Error when trying to inject a service into an angular component “EXCEPTION: Can't resolve all parameters for component”, why?

前端 未结 30 1850
无人共我
无人共我 2020-11-22 17:18

I\'ve built a basic app in Angular, but I have encountered a strange issue where I cannot inject a service into one of my components. It injects fine into any of the three o

30条回答
  •  迷失自我
    2020-11-22 17:43

    In my case, I was exporting a Class and an Enum from the same component file:

    mComponent.component.ts:

    export class MyComponentClass{...}
    export enum MyEnum{...}
    

    Then, I was trying to use MyEnum from a child of MyComponentClass. That was causing the Can't resolve all parameters error.

    By moving MyEnum in a separate folder from MyComponentClass, that solved my issue!

    As Günter Zöchbauer mentioned, this is happening because of a service or component is circularly dependent.

提交回复
热议问题