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.

MdDialog: Declaring MyDialogComponent in lazy-loaded module breaks app

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

  1. I declare MyDialogComponent in sub-module in declarations: [MyDialogComponent] and entryComponents: [MyDialogComponent]
  2. I open MyDialogComponent with this.dialog.open(MyDialogComponent);
  3. I see MyDialogComponent as a dialog open up.

What is the current behavior?

Running step 2 I get the following error:

error_handler.js:50 EXCEPTION: Error in ./HistoryComponent class HistoryComponent - inline template:12:28 caused by: No component factory found for MyDialogComponent. Did you add it to @NgModule.entryComponents? error_handler.js:52 ORIGINAL EXCEPTION: No component factory found for MyDialogComponent. Did you add it to @NgModule.entryComponents?

I have clearly added it to the sub-modules declarations and entryComponents.

// --- module.ts --- //
@NgModule({
    imports: [
        SharedModule,
        MdDialogModule,
    ],
    exports: [],
    declarations: [
        HistoryComponent,
        MyDialogComponent,
    ],
    providers: [],
    entryComponents: [
        MyDialogComponent
    ]
})
export class HistoryModule { }

// --- component.ts --- //
import { Component } from '@angular/core';
import { MdDialog, MdDialogRef } from '@angular/material/dialog';
import { MyDialogComponent } from './my-dialog.component';

@Component({
    selector: 'app-history',
    templateUrl: './history.component.html',
    styleUrls: ['./history.component.scss']
})
export class HistoryComponent {

    dialogRef: MdDialogRef<MyDialogComponent>;

    constructor(
        private dialog: MdDialog
    ) { }

    showDialog() {
        this.dialogRef = this.dialog.open(MyDialogComponent, {
            disableClose: false
        });

        this.dialogRef.afterClosed().subscribe(result => {
            console.log('result', result);
            this.dialogRef = null;
        });
    }
}

The interesting thing is, that when I add and declare the MyDialogComponent in the main app.module.ts the dialog opens up just fine.

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

angular-cli: 1.0.0-beta.24 node: 6.7.0 os: linux x64 @angular/common: 2.4.1 @angular/compiler: 2.4.1 @angular/core: 2.4.1 @angular/forms: 2.4.1 @angular/http: 2.4.1 @angular/material: 2.0.0-beta.1 @angular/platform-browser: 2.4.1 @angular/platform-browser-dynamic: 2.4.1 @angular/router: 3.1.1 @angular/compiler-cli: 2.4.1

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
jlutz777commented, Jan 4, 2017

@ciesielskico Are you using lazy loading for your submodule? I am running into the exact same problem, but only when using lazy loading.

2reactions
karolmie1commented, Jan 12, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Material dialog in lazy loaded module
You need to import MatDialogModule directly in MyLazyLoadedModule . ... array of the module where your dialog components are declared.
Read more >
Lazy load & split your Angular Material dialogs!
Our lazy loaded DialogModule would have its own router-outlet and therefore child routes. The main route will render the wrapper component, ...
Read more >
MEAN App: Reactive Programming
Learn from a Google Developer Expert: Part 3: Let's build an Angular app using reactive programming with RxJS and ngrx.
Read more >
angular material - Muhammad Hassan
Import the Angular Material NgModule in src/app/app.module.ts ... I saw this error popping up while including Dialog material component into my module.
Read more >
md-dialog does not work in seperate module.
I tried using md-dialog in different module other than the root AppModule and ... but that sort of defeats the purpose of modules...
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