Modal: Open components from lazy loaded modules

Bug description:

If I create a component, to be loaded by the modal-service, in a lazy-loaded route it can not be resolved with the error:

Error: No component factory found for CustomModalContentComponent. Did you add it to @NgModule.entryComponents?
    at noComponentFactoryError (core.es5.js?de3d:3202)

And this is since it is created in another context for the lazy loaded module.

So I pass along the Injector from the component where I call the modal service, but that did not work as the ComponentResolveFactory for the current context is not used.

A fix would be to get the ComponentFactoryResolver from the passed injector.

modal-stack.ts

84: const contentCmptFactory = contentInjector.get(ComponentFactoryResolver).resolveComponentFactory(content);

I have tried to edit the downloaded npm package and tried to create a pull-request, but could not get the tests to pass as it could not fond an instance of ComponentFactoryModule.

Version of Angular, ng-bootstrap, and Bootstrap:

Angular: 4.3.6

ng-bootstrap: 1.0.0-beta.5

Bootstrap: 4.0.0-beta

1 possible answer(s) on “Modal: Open components from lazy loaded modules

  1. Hi guys I’m having the same issue. I also created a complete stackblitz that shows the issue I have. Could you please point me to the right direction? I don’t want to move my modal content into the main app.module!