我想将“ trackings”的值转换为数组。现在,它会打印一个对象。见下文:
我需要 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();
// });
}
谢谢您的帮助。
答案 0 :(得分:1)
您的addTrackingsToForm
正在向FormGroup
添加FormArray
。它应该添加一个FormControl
。在这种情况下,将其更改为control
而不是array
:
addTrackingsToForm(control) {
console.log(control);
control.push(
this.fb.control()
);
}