gpt4 book ai didi

angular - 如何从被调用组件内部访问 MatDialogConfig?

转载 作者:行者123 更新时间:2023-12-04 07:45:26 26 4
gpt4 key购买 nike

我在我的 spa 中使用 MatDialog,需要将 MatDialogConfig 传递给已调用的组件。有什么办法吗?

最佳答案

您可以使用 componentInstanceMatDialogRef<T> .只需获取对话框的引用即可获取 MatDialogRef :

打开对话框的方法:

openDialog(dialogConfig: MatDialogConfig) {
let dialogRef = this.dialog.open(MyDialogComponent);
// You can rename the dialogConfig instance to whatever you want. See the next code snippet for more info.
dialogRef.componentInstance.dialogConfig = dialogConfig;
}

对话框组件:

export class MyDialogComponent implements OnInit {
// Rename the property to whatever you want it to be
dialogConfig: MatDialogConfig;
ngOnInit() {
console.dir(`Dialog config: ${this.dialogConfig}`);
}
}

关于angular - 如何从被调用组件内部访问 MatDialogConfig?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49675775/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com