this.formGroup = this.formBuilder.group({
images: this.fb.array([])
});
我这样添加新元素:
this.images.push(new FormControl(new ImageCreateForm(this.imageResponse.id)));
get images(): FormArray {
return <FormArray>this.formGroup.controls.images;
}
我的课程:
export class ImageCreateForm {
id: number;
constructor(id: number) {
this.id = id;
}
}
export class ImageResponse {
id: number;
url: string;
}
当我添加图片后,我的
{{ formGroup.value | json }}
是:"images": [
{
"id": 501
},
{
"id": 502
},
{
"id": 503
}
]
我想在发送表单POST请求之前从formGroup
中删除图片(例如仅使用id = 502
的图像)。这可能吗?我尝试使用reset
方法,但这会删除所有元素:this.images.reset({"id":image.id});
其中image
是一个ImageResponse
对象。
结果:{"images": [ null, null, null ]}
,但我需要:
"images": [
{
"id": 501
},
{
"id": 503
}
]
values
数组中。 - Chris Halcrow