angular - Angular FormArray 值作为数组,而不是对象
问题描述
我想将“跟踪”的值转换为数组。现在,它打印一个对象。见下文:
我需要trackings成为一个数组: trackings: ['value','value']
在我当前的代码下方:
interface FormInterface {
items: [{
sku: string;
quantity: string;
received: string;
trackings: Array < any > ;
}];
orderId: string;
isPrime: boolean;
reason: string;
}
addItemToForm() {
const items = this.fb.group({
sku: ['', Validators.required],
quantity: ['', Validators.required],
received: ['', Validators.required],
trackings: this.fb.array([])
});
this.itemsForm.push(items);
}
addTrackingsToForm(control) {
console.log(control);
control.push(
this.fb.group({
trackings: [] as Array < any >
})
);
}
submitData() {
console.log( < FormInterface > this.inputData.value);
// this.returns.createReturn(this.inputData.value).subscribe(data => {
// this.returns.openSnackBar('Return Created!', '');
// this.inputData.reset();
// });
}
感谢您的帮助。
解决方案
您addTrackingsToForm
正在FormGroup
向FormArray
. 它应该添加一个FormControl
。在这种情况下将其更改control
为array
:
addTrackingsToForm(control) {
console.log(control);
control.push(
this.fb.control()
);
}
推荐阅读
- python - 如何使用odoo python api提取数据?
- next.js - 如何使用tailwind css垂直放置屏幕的项目中心
- python - 网络抓取 finviz 以获取有关市值的基本数据
- github-actions - Github 操作失败:“作业”中未定义作业
- python - Cython:数学表达式错误(在 Python 中工作正常)
- download - 使用 Python 或 wget/curl 从 Google-Drive 下载整个公用文件夹,无需身份验证
- next.js - react-spring useTransition 钩子在图像滑块中不起作用
- javascript - 错误:找不到绑定文件。试过:
- wordpress - Wordpress 中的错误“注意:尝试访问 null 类型值的数组偏移量”
- javascript - 在装饰器中获取原始方法的文件路径?