没有对话框组件类

时间:2018-01-19 06:40:36

标签: angular modal-dialog angular-material angular-material2 angular5

是否可以在不创建对话框组件的情况下打开带有视图子参考的角度材质2对话框?

1 个答案:

答案 0 :(得分:12)

试试这个

View.html

 <button (click)="openModal(mytemplate)">Open my template</button>

    <ng-template #mytemplate>
        <h1>It works</h1>
    </ng-template>

component.ts

 openModal(templateRef) {
            let dialogRef = this.dialog.open(templateRef, {
                width: '250px',
                // data: { name: this.name, animal: this.animal }
            });

            dialogRef.afterClosed().subscribe(result => {
                console.log('The dialog was closed');
                // this.animal = result;
            });
        }