Reputation: 1697
How to get data sent to a MatDialog that is a ng-template
?
Template
<button mat-button (click)="openDialog()">Open</button>
<ng-template #dialogRef>
{{data?}} <!-- <<< Here is the problem data is undefined -->
</ng-template>
Component
export class SomeComponent {
@ViewChild("dialogRef") dialogRef: TemplateRef<any>;
constructor(private dialog: MatDialog) { }
openDialog(): void {
this.dialog.open(this.dialogRef, { data: "some data" });
}
}
Upvotes: 28
Views: 16178
Reputation: 214175
It should be available through template variable:
<ng-template #dialogRef let-data>
^^^^^^^^
{{data}}
</ng-template>
Upvotes: 41