fix(modal): modal does not properly work in a lazy loaded module
See original GitHub issueTo have working modal in a lazy-loaded module you have to import modal module with forRoot()
in that lazy module which is not correct as BsModalService
will get a new instance and will not know anything about other modals of other modules (e.g. nesting won’t properly work). If you skip the forRoot()
you will get:
ERROR Error: No component factory found for MyModalInLazyLoadedModule.
Did you add it to @NgModule.entryComponents?
That’s happening because ComponentLoaderFactory is provided only in root module which does not know anything about lazy-loaded injector and factories.
Proper fix would be to have some kind of overlay service that is provided with every ModalModule import.
Reproduction - https://stackblitz.com/edit/ngx-bootstrap-playground-mtwpzg
Issue Analytics
- State:
- Created 6 years ago
- Reactions:37
- Comments:25 (1 by maintainers)
Top Results From Across the Web
How to solve the EntryComponent issue while doing lazy ...
As this is Lazy loading of components so I dont want to declare EditProfileComponent in app.module.ts. Detailed code is as below:- app-routing.
Read more >ngx-smart-modal/Lobby - Gitter
I'm using the ngx-smart-modal with lazy loaded modules. But i'm having trouble with getting everything to work correctly. Mainly with getting modals to...
Read more >Lazy-loading feature modules - Angular
You can verify that a module is indeed being lazy loaded with the Chrome developer tools. In Chrome, open the developer tools by...
Read more >Lazy load modals with Angular! | by Parham | Code道 - Medium
To lazy load a feature module you can simply define a route for it and that's it! Here is an example to remind...
Read more >Angular Modules and NgModule - Complete Guide
A lazy-loaded Angular module works just like a feature module, but the difference is that by default, Angular creates a separate dependency ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@psined1 Just import
ModalModule.forRoot()
in your lazy-loaded module.Also having the same issue. The workaround pointed by @dzonatan fixes it, but I don’t know what are the implications of using forRoot in a child module.