Ngx-bootstrap: Modal cannot display component from dynamic module [Angular 8]

Created on 10 Jan 2020  路  5Comments  路  Source: valor-software/ngx-bootstrap

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

angular issue comp(modal)

All 5 comments

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

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()

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

entryComponents: [YourComponent],

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

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

Was this page helpful?
0 / 5 - 0 ratings