0

I was taking a look into the source code of an angular package. In one of the component declarations I see another component (SwingStackComponent) being injected.

export class SwingCardComponent {
  constructor(
    private elmentRef: ElementRef,
    private swingStack: SwingStackComponent) {
  }
}

How can a component be injected into another component? I think I am missing something here.

Here is the link to the repo.

JuanDM
  • 1,250
  • 10
  • 24
raj
  • 5,989
  • 7
  • 30
  • 62
  • SwingStackComponent is a parent component for SwingCardComponent – yurzui Nov 25 '17 at 13:46
  • It means if you try to use `[swing-card]` attribute without parent element with `[swing-stack]` attribute you will get an error `No provider for SwingStackComponent` – yurzui Nov 25 '17 at 13:48
  • So a parent component can be injected into a child component just like a service ? – raj Nov 25 '17 at 14:02
  • Yes. See also `Where does angular compiler take providers?` https://stackoverflow.com/questions/46332859/angular-2-how-does-ng-bootstrap-provide-the-ngbradiogroup-and-ngbbuttonlabel-t/46376298#46376298 – yurzui Nov 25 '17 at 14:05
  • In all documentation it mentions that all the providers listed in a component/directive will be added to providers pool. Not the component and directives. And DI looks up the tree in this providers pool. How is component and directives get added to providers without @injectable() ? – raj Nov 25 '17 at 16:14

0 Answers0