I am currently using Angular 4's asynchronous compiler to dynamically load an external module and add one of its components into the DOM using NgComponentOutlet. The external module is meant to be functionally disjoint from the main application, and as such it should have its own, unique dependency injector (or rather, an injector without access to the providers of the parent module). However, if I create a new dependency injector using ReflectiveInjector.resolveAndCreate
, NgComponentOutlet fails with the error No provider for NgModuleRef!
.
After some tracing through NgComponentOutlet, this seems to be because the NgModuleFactory depends on renderers, etc. in order to create the component. However, I've been unable to find an API that exposes a minimal dependency injector akin to the one provided to the root module. Is there any way to obtain this injector, or to create a minimal dependency injector that still contains the necessary resources for rendering a dynamically compiled component?