I am trying to set-up a stackblitz example to ask a more complex question about an issue I am having with testing.
However, when setting up the basic example, while my basic test passes, clicking on the button to get the MatDialog to show throws an error that the ComponentFactory cannot be found. But I have added it to declarations and entryComponent in app.module.ts. What am I missing.?
p.s. The code itself works in my larger project, it is something about the way I am setting it up in Stackblitz that seems to be the issue.
p.p.s Based on Maihan's answer below, it got me thinking about the idea itself. Even though it builds and run, the idea complains about not being able to find the AddUserDialog component. But not sure why.
app.component.ts
import { Component } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material';
import { AddUserDialogComponent } from './AddUserDialogComponent';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
constructor(public dialog: MatDialog){
};
openAddUserDialog(): void{
const dialogConfig = new MatDialogConfig();
dialogConfig.data = {
employeeList:['foo', 'bar'],
roles: ['fiz', 'faz']
};
const dialogRef = this.dialog.open(AddUserDialogComponent, dialogConfig);
dialogRef.afterClosed().subscribe((data) => {
console.log('hello');
});
}
}
app.module.ts
import { NgModule } from '@angular/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { MatDialogModule, MatDialogRef, MatDialog } from '@angular/material/dialog';
import { AddUserDialogComponent } from './AddUserDialogComponent';
import { AppComponent } from './app.component';
@NgModule({
imports: [ BrowserModule, FormsModule, MatDialogModule, NoopAnimationsModule ],
declarations: [ AppComponent, AddUserDialogComponent ],
exports: [AppComponent, AddUserDialogComponent],
entryComponents: [ AddUserDialogComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }