简体   繁体   中英

MatDialog - open a component passing a @Input()

I need to open a component using the method open(MyComponent, myConfig) of the class MatDialog but with a @Input() added to the opened component. How can I do that?

Use the data property to pass the wanted datas.


constructor(private dialog: MatDialog){}

this.diaog.open(YOUR_COMPONENT, {
  data: {} // What you want
  ... // Others properties
});

Then in YOUR_COMPONENT:

constructor(@Inject(MAT_DIALOG_DATA) public data: any) {
  console.log(this.data);
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM