是否可以在不创建对话框组件的情况下打开带有视图子参考的角度材质2对话框?
答案 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;
});
}