MdDialog: Declaring MyDialogComponent in lazy-loaded module breaks app
See original GitHub issueBug, feature request, or proposal:
Bug
What is the expected behavior?
- I declare
MyDialogComponent
in sub-module indeclarations: [MyDialogComponent]
andentryComponents: [MyDialogComponent]
- I open
MyDialogComponent
withthis.dialog.open(MyDialogComponent);
- 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:
- Created 7 years ago
- Reactions:11
- Comments:12 (4 by maintainers)
Top GitHub Comments
@ciesielskico Are you using lazy loading for your submodule? I am running into the exact same problem, but only when using lazy loading.
duplicates: https://github.com/angular/material2/issues/1765