小编Muh*_*fan的帖子

如何删除angular2反应形式的FormArray

我在从ReactiveForm删除FormArray时遇到问题。

我有以下代码:

ngOnInit() {
  this.survey = new FormGroup({
    surveyName: new FormControl(''),
    sections: new FormArray([
      this.initSection(), 
    ]), 
  });      
}

initSection(){
  return new FormGroup({
    sectionTitle : new FormControl(''),
    sectionDescription : new FormControl(''),
  });
}

addSection(){
  const control = <FormArray>this.survey.controls['sections'];
  control.push(this.initSection());
}
Run Code Online (Sandbox Code Playgroud)

现在要删除formControl surveyName我只是做

this.survey.removeControl('surveyName');
Run Code Online (Sandbox Code Playgroud)

上面的代码对于SurveyName工作正常。但是我可以使用什么删除表单数组部分。我想用键删除整个节对象。

angular

4
推荐指数
1
解决办法
6538
查看次数

标签 统计

angular ×1