angular - 以角度将数组数据传递给matdialog
问题描述
我想使用 angular 将数组数据传递给 Matdialog,对于单个数据它可以工作,但如何传递数组数据。
我调用对话框的组件
分销商订单.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;
});
}
在这里,我如何使用这个单一数据发送数组数据。
解决方案
您需要将数组嵌入数据对象中 - 就像您将任何其他数据发送到对话框一样。然后,在这种情况下,您可以使用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;
});
}
推荐阅读
- node.js - 如何更改 npm ll 的输出格式?
- android - 菜单文件夹中的 android:actionLayout 创建 Android 操作栏不起作用吗?
- r - 使用 read.csv 导入文件时出现问题
- windows - Windows 10 中的主文件夹是否有别名?
- javascript - 第一个字母重复时名称的格式大小写
- html - 如何在响应式下拉菜单中制作链接到 href 的特定字母或锚标记的一部分
- javascript - PHP 表单执行后的导航
- javascript - 如何将代码和单元测试通过管道传输到 npm test?
- angular - 从模板 *ngfor 获取索引以用于我的打字稿类
- makefile - Makefile中的单个OR字符是什么