shlomiassaf / ngx-modialog

Modal / Dialog for Angular
http://shlomiassaf.github.io/ngx-modialog
MIT License
686 stars 242 forks source link

Lazy Loading a Module bug. #366

Closed alfonsserra closed 7 years ago

alfonsserra commented 7 years ago

IMPORTANT: Please provide a sample using:

Report a Bug.

Lazy loading is not working well. Once I load my module with lazy loading, at the moment that I'm going to show the modal inside the module, I have the following error:

ModalOverlay.html:1 ERROR Error: No component factory found for 'Dialog Class Name'. Did you add it to @NgModule.entryComponents?

In the module, of course, I have the 'Dialog Class Name' in the NgModule.entryComponents, and everything is working fine when do not lazy load the module.

shlomiassaf commented 7 years ago

Can you provide a sample repo so I can reproduce?

Sent from my iPhone

On Jun 20, 2017, at 9:14 PM, Alfons Serra notifications@github.com wrote:

IMPORTANT: Please provide a sample using:

I'm submitting a ... [X] bug report [ ] feature request [ ] question about the decisions made in the repository

Do you want to request a feature or report a bug?

Report a Bug.

What is the current behavior? Lazy loading is not working well. Once I load my module with lazy loading, at the moment that I'm going to show the modal inside the module, I have the following error:

ModalOverlay.html:1 ERROR Error: No component factory found for 'Dialog Class Name'. Did you add it to @NgModule.entryComponents?

In the module, of course, I have the 'Dialog Class Name' in the NgModule.entryComponents, and everything is working fine when do not lazy load the module.

Library version: 3.0.0 Angular version: 4.0.0 Browser: [all ] — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

shlomiassaf commented 7 years ago

Ok, problem is opening a module with an injector that does not know how to resolve the component since the component belongs to another injector.

Say you have 2 modules, A & B, B loads lazy.

From the main page that is in A you are trying to open a component declared in B.
You are not providing an injector when you open (which is fine)... so the library uses the default injector which is the root injector from the main module A.

The injector from A does not know about B, you actually need an injector from B and it will work.

I will post a fix with a workaround that keeps a current injector at the service at all times to make sure this wont happen, since the service init's on each DI hit it should be current.

shlomiassaf commented 7 years ago

try version 3.0.1

alfonsserra commented 7 years ago

Dear Shlomi: It works!

With the change you did in version 3.0.1. and by adding the right providers in the lazy loaded module, works fine.