【发布时间】:2018-05-04 15:39:45
【问题描述】:
我正在研究 Angular 表单数据驱动方法,我将表单控件动态添加到 FormArray,我使用 form.reset() 重置添加的控件,但 form.reset() 不会重置 FormArray 长度,我发现这是一个已知问题,可以使用这种方法解决,https://github.com/angular/angular/pull/11051,但我仍然不清楚这一点。请帮忙,谢谢
reviewForm: FormGroup;
ngOnInit(){
this.reviewForm = new FormGroup({
'controlArray': new FormArray([
])
});
}
onSubmit(){
this.formData = new FormData(this.formService.formName, this.reviewForm.value.controlArray);
let formControls = JSON.stringify(this.formData);
// console.log(formControls);
this.formService.createForm(formControls)
.subscribe(
data => console.log(data),
error => console.error(error)
);
this.reviewForm.reset();
}
【问题讨论】:
标签: angular angular-reactive-forms