Can anyone help me figure out how to dynamically call a method of a component using ngComponentOutlet?
Here's an example code snippet from my Caller:
this.dialog.open(FormDialogComponent, {data: {body: ChildComponent}});
In the FormDialogComponent:
export interface FormDialogData {
title: string,
body: Type<any>
}
export class FormDialogComponent {
@ViewChild(ChildComponent) child!: ChildComponent;
constructor(public dialogRef: MatDialogRef<FormDialogComponent>, @Inject(MAT_DIALOG_DATA) public data: FormDialogData) {}
save(){
this.child.save(); // trying to call save() method of childComponent but it's not working
}
}
Any ideas on how I can successfully call the save method of my child component?
ADD
Oh, I forgot to include the html part:
<ng-container [ngComponentOutlet]="data.body" #child></ng-container>