没有对话框组件类的Angular Material viewchild对话框

Sha*_*una 7 modal-dialog angular-material angular-material2 angular angular5

有没有办法我可以打开角度材料2对话框与视图子参考,而无需创建对话框组件?

Dil*_*elo 15

试试这个

View.html

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

    <ng-template #mytemplate>
        <h1>It works</h1>
    </ng-template>
Run Code Online (Sandbox Code Playgroud)

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;
            });
        }
Run Code Online (Sandbox Code Playgroud)