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

前端 未结 30 1950
无人共我
无人共我 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:29

    In my case, the reason was the following:

    • my injectable service A extended another class B
    • B had a constructor which required an argument
    • I hadn't defined any constructor in A

    As a consequence, when trying to create an object A, the default constructor failed. I have no idea why this wasn't a compile error.

    I got it fixed by simply adding a constructor in A, which correctly called B's constructor.

提交回复
热议问题