Angular “将正文文本添加到mat”对话框
我试图向mat对话框添加一些正文文本,但似乎无法传递文本Angular “将正文文本添加到mat”对话框,angular,angular-material,Angular,Angular Material,我试图向mat对话框添加一些正文文本,但似乎无法传递文本 openDialog(): void { const dialogRef = this.dialog.open(ConfirmComponent, { width: '350px', data: "Do you accept these terms and conditions?" }); dialogRef.afterClosed().subscribe(
openDialog(): void {
const dialogRef = this.dialog.open(ConfirmComponent, {
width: '350px',
data: "Do you accept these terms and conditions?"
});
dialogRef.afterClosed().subscribe(result => {
if(result) {
console.log('Yes clicked');
}
});
}
对话框组件
public dialogRef:MatDialogRef,
@注入(MAT_对话框_数据)公共标题:字符串,
@注入(MAT_对话框_数据)公共消息:字符串,
{{title}}
{{message}}
不
对
因此,我试图将标题和消息传递给对话框中的数据,@Inject(MAT_dialog_data)
将注入您的数据。您不能使用它两次,只能使用一次,例如:
@Inject(MAT_DIALOG_DATA) public data: {title: string; message: string}
<h2 mat-dialog-title>{{data.title}}</h2>
<div mat-dialog-content>
{{data.message}}
</div>
@Inject(MAT\u DIALOG\u DATA)
将注入您的数据。您不能使用它两次,只能使用一次,例如:
@Inject(MAT_DIALOG_DATA) public data: {title: string; message: string}
<h2 mat-dialog-title>{{data.title}}</h2>
<div mat-dialog-content>
{{data.message}}
</div>