1

I just noticed that I can use a component without declaring in any module it as long as it has its own route. So, is it correct to remove all the directly routed components from the declarations array? Is this new behavior in angular or maybe I just don't remember correctly.

You can see in my stackblitz that the "cat" component is not declared but still loading on the button click.

Udi Mazor
  • 1,646
  • 2
  • 15
  • 30

1 Answers1

0

Possible duplicate of this

Seems like: router-outlet will auto generate component by ComponentFactoryResolver

In other words below will throw error if you access without declaring:

<app-cats> </app-cats>
Vugar Abdullayev
  • 1,852
  • 3
  • 21
  • 46
  • I also noticed that although the component will load it will not be able to use other components or directives if not included in the module that has access to those components or directives – Udi Mazor Sep 10 '21 at 17:29
  • 1
    So it means it only injects that component. Not dependencies. – Vugar Abdullayev Sep 10 '21 at 17:34