我正在从组件中打开一个对话框。
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');
});