【问题标题】:Pass array data to matdialog in angular以角度将数组数据传递给matdialog
【发布时间】:2019-03-28 12:47:19
【问题描述】:

我想使用 angular 将数组数据传递给 Matdialog,对于单个数据它可以工作,但如何传递数组数据。

我调用对话框的组件

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

我怎样才能用这个单一的数据发送数组数据。

【问题讨论】:

    标签: angular


    【解决方案1】:

    您需要将数组嵌入到数据对象中 - 就像您将任何其他数据发送到对话框一样。在这种情况下,您可以使用 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;
       });
    }
    

    【讨论】:

    • 感谢您的建议。
    猜你喜欢
    • 1970-01-01
    • 2021-04-09
    • 2018-05-08
    • 2015-09-22
    • 1970-01-01
    • 2017-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多