0

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?

ANewGuyInTown
  • 5,957
  • 5
  • 33
  • 45
  • That link suggests you using special dictionary so that you do not need using private property. What do you by "inject via url"? – yurzui Jul 18 '18 at 06:18
  • @yurzui, meaning, if component is not known at compile time as it is in the higher layer of abstraction (feature layer using shared where the component is), at runtime, we could "get the component using the URL to the component), something like ` let thisIsRequiredComponent=getComponent("UrlToTheComponent")` – ANewGuyInTown Jul 19 '18 at 01:49

0 Answers0