简体   繁体   English

以角度将数组数据传递到Matdialog

[英]Pass array data to matdialog in angular

I want to pass array data to Matdialog using angular ,for single data it working but how to pass array data. 我想使用angular将数组数据传递给Matdialog,对于单个数据,它可以工作,但是如何传递数组数据。

My component where i call dialog 我调用对话框的组件

distributor-order.component.ts distributor-order.component.ts

openDialog(address, city, pin, phone, orderid, orderstatus, totalprice, updateby, updatedate): void {
    console.log(address);
    const dialogRef = this.dialog.open(OrderDialogComponent, {
       width: '1000px',
       data: {
           Address: address, 
           City: city, 
           Pin: pin, 
           phone:phone,
           Orderid: orderid, 
           Orderstatus: orderstatus,
           Totalprice: totalprice,
           Updateby: updateby,
           Updatedate: updatedate
       }
   });
   dialogRef.afterClosed().subscribe(result => {
      console.log('The dialog was closed');
      //this.animal = result;
   });
}

Here how can i send array data with this single data. 在这里,我如何使用该单个数据发送数组数据。

You need to embed the array inside the data-object - the same way you are sending any other data to the dialog. 您需要将数组嵌入到数据对象内部,就像将其他任何数据发送到对话框一样。 Then you can get it inside the dialog with this.data.arrayForDialog in this case. 然后,在这种情况下,您可以使用this.data.arrayForDialog在对话框中获取它。

openDialog(address, city, pin, phone, orderid, orderstatus, totalprice, updateby, updatedate): void {
    let myArray = [{name: 'jon'}, {name: 'bob'}];
    const dialogRef = this.dialog.open(OrderDialogComponent, {
       width: '1000px',
       data: {
           arrayForDialog: myArray,
           Address: address, 
           City: city, 
           Pin: pin, 
           phone:phone,
           Orderid: orderid, 
           Orderstatus: orderstatus,
           Totalprice: totalprice,
           Updateby: updateby,
           Updatedate: updatedate
       }
   });
   dialogRef.afterClosed().subscribe(result => {
      console.log('The dialog was closed');
      //this.animal = result;
   });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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