Trying to make a dialog using feature model in angular 6. But I'm getting this error:
No component factory found for DialogModule. Did you add it to @NgModule.entryComponents?
Everyone keeps saying to use
entryComponents: [DialogComponent]
which I am already doing. Also tried to use that in the feature module without success. Here are I think the necessary and simplified files:
app.module.ts
import { DialogModule } from './components/dialog/dialog.module';
import { DialogComponent } from './components/dialog/dialog.component';
...
// AoT requires an exported function for factories
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
}
@NgModule({
declarations: [..., AppComponent],
imports: [DialogModule],
entryComponents: [DialogComponent],
providers: [..., MatDialogModule],
bootstrap: [AppComponent]
})
export class AppModule {}
dialog.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DialogComponent } from './dialog.component';
...
@NgModule({
imports: [
CommonModule
],
declarations: [..., DialogComponent],
exports: [DialogComponent]
})
export class DialogModule {
...
}
some-other.component.ts
import { DialogModule } from '../../components/dialog/dialog.module';
...
@Component({
...
})
export class LanguageButtonComponent implements OnInit {
constructor(private languageService : LanguageService,
private dialog: MatDialog,) {
}
// activated from button
openDialog() {
this.dialog.open(DialogModule);
}
}
How to get rid of the error?
You have to put your DialogComponent
in entryComponents
of DialogModule
and not in AppModule
:
entryComponents
in the correct module
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DialogComponent } from './dialog.component';
...
@NgModule({
imports: [
CommonModule
],
declarations: [DialogComponent],
exports: [DialogComponent],
entryComponents: [DialogComponent],
})
export class DialogModule {
...
}
entryComponents
from AppModule