【发布时间】:2018-09-25 03:40:28
【问题描述】:
我想在 Angular 6 中创建一个具有多个内容项目的组件。它可能是
这是我从app.component.html传递过来的内容:
<popup>
<button buttonTrigger mat-button><span >Open the popup!</span></button>
<my-dialog-content content></my-dialog-content>
</popup>
这是popup.component.html的内容
<div (click)="openDialog()"><ng-content select="[buttonTrigger]" ></ng-content></div>
<ng-template #dialogContent>
<ng-content select="[content]"></ng-content>
</ng-template>
这是对话内容的内容:
<mat-dialog-content>
my-dialog-content works!
</mat-dialog-content>
<mat-dialog-actions align="end">
<ng-container ngProjectAs="btn-close"><button mat-button color="warn" matDialogClose>Close</button></ng-container>
<button mat-button color="primary" type="submit" cdkFocusInitial>Submit</button>
</mat-dialog-actions>
这似乎工作除了关闭按钮:
ERROR TypeError: Cannot read property 'close' of null
这是我的源代码的链接:https://stackblitz.com/edit/multiple-ngcontent
我不知道是否会有解决此问题的解决方案或好主意。
谢谢!
【问题讨论】:
标签: angular angular-material dialog