There is a shared module and there is a feature module.
Shared module has a shared component and has a view container (ng-container
) to inject a component dynamically.
Since, shared component has no knowledge of feature module as feature module is a dependent on shared not the other way around, how is it possible to inject the component dynamically without the knowledge of component type at compile time? And to make matter worse, the shared component is instantiated via URL and not part of the template itself. What I mean is:
in feature module the shared component is navigated via:
this.navigateViaUrl("urlToTheSharedComponent")
I tried using reflection something similar as described in this link However, I do not want to use the private variable as it is not future proof.
const factories = Array.from(this.resolver['_factories'].values());
const factory = factories.find((x: any) => x.selector === selector);
Is there anyway to inject component via URL within ng-template or ng-container
? Or is there any other way?