angular - 如何访问有角材料弹出/对话框组件内的组件属性?
问题描述
我正在从我的组件中打开一个对话框。
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '500px',
data: DialogData
});
dialogRef.afterClosed().subscribe(result => {
this.dialogData = new DialogData('label...',this.frequency,'action','screen_ocr','parameter_type','parameter_value',0,'next_node',1,'index',false);
console.log('The dialog was closed');
});
我想从这个组件访问几个属性来初始化 DialogOverviewExampleDialog
@Component({
selector: 'dialog-overview-example-dialog',
templateUrl: 'dialog-overview-example-dialog.html',
})
export class DialogOverviewExampleDialog {
//here I want to use properties of my component
constructor(private dialogService: DialogDataService,
public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
@Inject(MAT_DIALOG_DATA) public data: DialogData) {}
唯一的方法,我可以弄清楚这是使用 rxjs 的 behaviorsubject 来访问属性,但是这个 DialogOverviewExampleDialog 是在我的组件内部声明的。有没有办法在 DialogOverviewExampleDialog 中直接访问我的组件的属性?反之亦然。
谢谢,
解决方案
用这个:dialogRef.componentInstance.YOUR_PROPERTY
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '500px',
data: DialogData
});
dialogRef.componentInstance.YOUR_PROPERTY
dialogRef.afterClosed().subscribe(result => {
this.dialogData = new DialogData('label...',this.frequency,'action','screen_ocr','parameter_type','parameter_value',0,'next_node',1,'index',false);
console.log('The dialog was closed');
});
推荐阅读
- crash-reports - 升级到iOS12后应用程序在启动时立即崩溃
- python - 比较两个不同列表中的不同元素
- tree - 使用顺序检查 BST
- css - 在一个里面
不会移动到底部 - ruby-on-rails - 使用comfort_mexican_sofa 时出现与Turbolinks 相关的错误
- c++ - 使用 cpprest (Casablanca) 返回 PDF 响应
- c - 在 Linux 上测试 SIGINT 和 SIGHUP 时出现有趣的类似故障的行为
- php - 如何根据输出编写mysql查询?
- json - jq raw json输出回车?
- cakephp - 在 cakephp 3 中将数组转换为 Cake\ORM\Query 对象