Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular dynamic component can't use component from different module

This is the scenario (check this Stackblitz):

  • I have two modules: AppModule and OtherModule.
  • In AppComponent (from AppModule), I create two dynamic components, using
    FirstComponent and SecondComponent.
  • In the FirstComponent template I insert HelloComponent, that belongs to the same module (AppModule), and it works fine.
  • The problem comes in the SecondComponent, where I insert ThirdComponent, that belongs to OtherModule. I receive the error: ‘third’ is not a known element.
  • OtherModule is imported in AppModule.
  • If I remove <third></third> from second.component.html the app will run, but I need to insert ThirdComponent inside SecondComponent, and SecondComponent is dynamic.

So, how can I use inside a dynamic component a component from a different module?

Angular CLI: 12.0.1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have to export the components that throw errors. What I mean is that you need to include the third component in the exports array in OtherModule. It should work.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading