valor-software / ngx-bootstrap

Fast and reliable Bootstrap widgets in Angular (supports Ivy engine)
https://valor-software.com/ngx-bootstrap
MIT License
5.53k stars 1.69k forks source link

Modal cannot display component from dynamic module [Angular 8] #5591

Open pgrzywaczcic opened 4 years ago

pgrzywaczcic commented 4 years ago

When trying to display a modal with a component from a dynamically loaded module and using BsModalService registered in AppModule, it fails:

Error: No component factory found for XXXComponent. Did you add it to @NgModule.entryComponents?

The only workaround I found was to have ModalModule.forRoot() registered in the dynamic module, however this is not optimal.

This issue wasn't present in Angular 6

I tested this with ngx-bootstrap 5.4.0, 5.3.2, 5.20 and Angular 8.2.16

exequiel09 commented 4 years ago

I think this is related to this https://github.com/angular/angular/issues/14324. I have encountered that same problem using modals.

pgrzywaczcic commented 4 years ago

I think it is. Since they are calling this a feature, maybe a workaround is needed?

Some guy suggested storing ComponentFactoryResolver aware of that component somewhere where it can be retrieved. So if I know a component will be rendered with BsModalService, I can first register that component with it's ComponentFactoryResolver instance.

An other solution would be to allow passing a ComponentFactoryResolver instance to BsModalService.show()

hackermanmx commented 4 years ago

For anyone having this issue: Try adding this in the Module it's declared.

entryComponents: [YourComponent],

exequiel09 commented 4 years ago

@DeeNeon It's not as simple as that when the module that contains the entryComponents declaration is lazy loaded.

hackermanmx commented 4 years ago

Don't use it in a lazy loaded module then and use a shared.module :)