Skip to content

Getting "No component factory" error while opening a Material Dialog in lazy loaded Component #8473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nithindan opened this issue Nov 16, 2017 · 19 comments
Labels
needs: clarification The issue does not contain enough information for the team to determine if it is a real bug

Comments

@nithindan
Copy link

Hi,
Im getting the following error when i try to open Material Dialog in ConfirmBoxComponent.

No component factory found for ConfirmBoxComponent. Did you add it to @NgModule.entryComponents?

I have already added ConfirmBoxComponent in entryComponents list

    declarations: [
      ConfirmBoxComponent
    ],
    exports: [ConfirmBoxComponent],
    entryComponents: [
      ConfirmBoxComponent
    ],

The module that contain ConfirmBoxComponent is loaded via Lazy loading technique.

I'm not sure this is bug or not.

I'm using latest version of Angular and Material

   "@angular/core": "^5.0.0",
  "@angular/material": "^5.0.0-rc0"
@donroyco
Copy link
Contributor

Have you checked #1491?

@nithindan
Copy link
Author

nithindan commented Nov 16, 2017

Ya . But its not working for me .
I have added ConfirmBoxComponent in entry components of my lazy loaded Module. But i'm still getting that error.

here is my code ( Not complete code)
https://gist.github.com/nithindan/f1a027e4b8589c59af9ec763b0ffded8

@jelbourn jelbourn added the needs: clarification The issue does not contain enough information for the team to determine if it is a real bug label Nov 16, 2017
@jelbourn
Copy link
Member

Can you please share your entire NgModule setup?

@nithindan
Copy link
Author

@nithindan
Copy link
Author

@jelbourn Is there any way to fix this ?

@jelbourn
Copy link
Member

You need to import MatDialogModule in ConsumerModule in order for it to know about the entryComponents there

@nithindan
Copy link
Author

thanks a lot @jelbourn . it worked <3

@ruant
Copy link

ruant commented Apr 30, 2018

Is this still the solution for this issue? Or has something else changed as of late?
I can't seam to get this to work, this is basically the exact same setup I got, but only getting:
No component factory found for LoginDialogComponent

@travtarr
Copy link

In regards to Angular v6+: in case anyone is using the MatDialog service inside another injectable service and is using the { providedIn: 'root' } option for that service, you'll need to instead provide that service in the providers array of the module where your dialog components are declared.

@Max101
Copy link

Max101 commented Aug 27, 2018

@travtarr thanks so much for the answer.... I had that exact same issue.
Plus it also only started working after i killed off ng serve

In short: If you the service building your component is only provided in root, be sure to also provide it in the lazy loaded module!

Why does that need to be like this though?

@jingignoli
Copy link

@travtarr "you'll need to instead provide that service in the providers array of the module where your dialog components are declared." this will declare a new instance of the service so it's not possible to have a singleton in the app to launch dialog ?

@travtarr
Copy link

@jingignoli I didn't clarify in my original post, but you'll want to remove the providedIn: 'root' when you provide it in a module.

@jingignoli
Copy link

jingignoli commented Aug 31, 2018

@travtarr Thanks for your answer but the service will be scoped to the module.
I need a singleton in my app to control my modals.

@travtarr
Copy link

travtarr commented Aug 31, 2018

@jingignoli Then you'll probably need to place your modal component declarations in a non-lazy-loaded module to avoid this issue.

@jingignoli
Copy link

@travtarr this is not a solution for me :(
My application is really huge and i have to isolate and lazy load feature module.
My modals are really feature centric and need component from the feature module so this force me to load the entire module.

Btw, thanks for your time :)

@min-w-park
Copy link

@jingignoli have you addressed this issue? I have same issue as yours :(

@jingignoli
Copy link

@min-w-park no i haven't created an issue for this, i don't know if it's a bug or a normal behavior.

@liuxinqiong
Copy link

I have the same question about it,When I open lazyload module.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: clarification The issue does not contain enough information for the team to determine if it is a real bug
Projects
None yet
Development

No branches or pull requests

9 participants