I'm using angular material to open dialogs. I have a lot of components that are getting openend in dialogs but as a matter of good separation of concerns I want to avoid baking in dialog behavior to the compoent. I have have a wrapper component call dashboard-dialog that has a ng-content area and provides some basic functionality and styling.
I would love to be able to do something like this like I could do with tsx/react;
const dialogComp = `<app-dashboard-dialog><app-create-user-form (create)="handleCreate()" cancel="handleCancel()"></app-create-user-form></app-dashboard-dialog>`
this.dialog.open(dialogComp, { ... });
Is there anything like this that will work with mat-dialog? How can I avoid making a dialog wrapped version of a component when we decide to open the component in a dialog?
Currently I am creating a new dialog component ex create-user-form-dialog.component.ts that has same template as my wished for dialogComp variable. and now opening this new dialog component this.dialog.open(CreateUserFormDialog, { ... });
The dialog component has the dialog ref and data injected.
@Component({
selector: 'app-create-user-form-dialog',
template: `
<app-dashboard-dialog #dialog>
<app-create-user-form
[detail]="injected_detail"
(create)="createUser($event)"
(cancel)="cancel($event)"
>
</app-create-user-form>
</app-dashboard-dialog>
`,
styleUrls: []
})
export class CreateUserFormDialogComponent {
constructor(
public dialogRef: MatDialogRef<CreateUserFormDialogComponent>,
@Inject(MAT_DIALOG_DATA) public injected_detail: Info
) {}
So create-user-form.component.ts emits out the results of its buttons (save, cancel etc) and create-user-form-dialog.component.ts spits things back out via the dialogref.close method. Not sure how this complicates the situation and if ViewChild can still be used in some way.