This is the scenario (check this Stackblitz):
- I have two modules:
AppModule
andOtherModule
. - In
AppComponent
(from AppModule), I create two dynamic components, usingFirstComponent
andSecondComponent
. - In the
FirstComponent
template I insertHelloComponent
, that belongs to the same module (AppModule), and it works fine. - The problem comes in the
SecondComponent
, where I insertThirdComponent
, that belongs toOtherModule
. I receive the error: 'third' is not a known element. OtherModule
is imported inAppModule
.- If I remove
<third></third>
fromsecond.component.html
the app will run, but I need to insertThirdComponent
insideSecondComponent
, and SecondComponent is dynamic.
So, how can I use inside a dynamic component a component from a different module?
Angular CLI: 12.0.1
CodePudding user response:
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.