【问题标题】:MatDialog - open a component passing a @Input()MatDialog - 打开一个传递 @Input() 的组件
【发布时间】:2021-03-01 12:00:24
【问题描述】:

我需要使用 MatDialog 类的 open(MyComponent, myConfig) 方法打开一个组件,但将 @Input() 添加到打开的组件中。我该怎么做?

【问题讨论】:

    标签: angular frontend


    【解决方案1】:

    使用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);
    }
    

    https://material.angular.io/components/dialog/examples

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-10
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      相关资源
      最近更新 更多