Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send data to a TemplateRef MatDialog

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" });
    }
}
like image 662
Sébastien Avatar asked Nov 10 '18 12:11

Sébastien


1 Answers

It should be available through template variable:

<ng-template #dialogRef let-data>
                        ^^^^^^^^
   {{data}}
</ng-template>
like image 86
yurzui Avatar answered Nov 06 '22 15:11

yurzui