Reputation: 12015
There is dialog: public dialog: MatDialog
and method open() that opens dialog:
this.dialog.open(MyDialogComponent, conf);
Description of open()
is:
open<T, D = any, R = any>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>, config?: MatDialogConfig<D>): MatDialogRef<T, R>;
Does it mean I should pass first parameter as instance component?
Why in example we use MyDialogComponent
instead new MyDialogComponent()
? What if MyDialogComponent
has dependency injection in constructor?
Upvotes: 2
Views: 1421
Reputation: 24424
the object dialog will create that object dynamically and he DI will inject an dependence for you
this component as example the AService
will inject by the DI system
@Component({
selector: 'dialog-overview-example-dialog',
templateUrl: 'dialog-overview-example-dialog.html',
providers: [AService]
})
export class DialogOverviewExampleDialog {
constructor(
public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
@Inject(MAT_DIALOG_DATA) public data: DialogData , public AService:AService ) {
console.log(AService)
}
onNoClick(): void {
this.dialogRef.close();
}
}
Upvotes: 3