Skip to content
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

Mat-dialog: `no component factory found`. ComponentFactoryResolver not updating the list of factories when other module is loaded. #15822

Closed
DenisSemionov opened this Issue Apr 15, 2019 · 2 comments

Comments

Projects
None yet
1 participant
@DenisSemionov
Copy link

DenisSemionov commented Apr 15, 2019

What is the expected behavior?

No error should occur as in case with MatDialogModule.

But instead I get ERROR Error: No component factory found for *. Did you add it to @NgModule.entryComponents?

What is the current behavior?

I use custom service to wrap my dialogs into custom component. Service has 'openModalWindow' method, which uses MatDialogService and which is used to dynamically create dialogs.

public openModalWindow(component: ComponentType<{}>, config: MatDialogConfig): MatDialogRef<ModalWindowComponent> {
    // Resolve dialog component factory
    const componentFactory = this._componentFactoryResolver.resolveComponentFactory(component);

    // Open dialog with wrapper component
    const dialogRef = this._dialog.open(DialogWrapperComponent, config);

    // Add dialog content inside wrapper component
    dialogRef.componentInstance.viewContainerRef.createComponent(componentFactory);
}

What are the steps to reproduce?

  • Open dialog with openModalWindow method, pass component type as a parameter.
    Works: if component is registered in entryComponents and declarations in current module.

    Error occurs in these situations:

  1. Situation 1: If component_2 is registered in declaractions and entryComponents only in module_2, but passed from module_1, which imports module_2.
  2. Situation 2:
    2. 1. Navigate from module_1 to lazy loaded module_2.
    2. 2. Open dialog_2, registered in declarations and entryComponents of module_2, it will fail.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular CLI: 7.3.8
Node: 10.7.0
OS: win32 x64
Angular: 7.2.12

Is there anything else we should know?

@DenisSemionov DenisSemionov changed the title Mat-dialog: `no component factory found` when trying to open dialog from other module. Mat-dialog: `no component factory found` when trying to open other' module dialog or lazy loaded module' dialog. Apr 15, 2019

@DenisSemionov

This comment has been minimized.

Copy link
Author

DenisSemionov commented Apr 15, 2019

I'm not sure if it's an angular bug, trying to configure the custom dialog service provider correctly, so factory would combine all components.

Anyway, for some reasons ComponentFactoryResolver not updating the list of factories after other lazy modules are loaded.

@DenisSemionov DenisSemionov changed the title Mat-dialog: `no component factory found` when trying to open other' module dialog or lazy loaded module' dialog. Mat-dialog: `no component factory found`. ComponentFactoryResolver not updating the list of factories when other module is loaded. Apr 15, 2019

@DenisSemionov

This comment has been minimized.

Copy link
Author

DenisSemionov commented Apr 15, 2019

Closing, because it is a problem with ComponentFactoryResolver -> angular/angular repository.

angular/angular#14324

angular/angular#17168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.