question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fix(modal): modal does not properly work in a lazy loaded module

See original GitHub issue

To 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:open
  • Created 6 years ago
  • Reactions:37
  • Comments:25 (1 by maintainers)

github_iconTop GitHub Comments

23reactions
dzonatancommented, Oct 19, 2017

@psined1 Just import ModalModule.forRoot() in your lazy-loaded module.

11reactions
julianonunescommented, Apr 20, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found