【发布时间】:2021-03-01 12:00:24
【问题描述】:
我需要使用 MatDialog 类的 open(MyComponent, myConfig) 方法打开一个组件,但将 @Input() 添加到打开的组件中。我该怎么做?
【问题讨论】:
我需要使用 MatDialog 类的 open(MyComponent, myConfig) 方法打开一个组件,但将 @Input() 添加到打开的组件中。我该怎么做?
【问题讨论】:
使用data 属性传递想要的数据。
constructor(private dialog: MatDialog){}
this.diaog.open(YOUR_COMPONENT, {
data: {} // What you want
... // Others properties
});
然后在 YOUR_COMPONENT 中:
constructor(@Inject(MAT_DIALOG_DATA) public data: any) {
console.log(this.data);
}
【讨论】: