angular 2 remove all items from a formarray

后端 未结 15 1773
清歌不尽
清歌不尽 2020-12-07 15:30

I have a form array inside a formbuilder and i am dynamically changing forms, i.e. on click load data from application 1 etc.

The issue i am having is that all the

15条回答
  •  无人及你
    2020-12-07 16:09

    You can easily define a getter for your array and clear it as follows:

      formGroup: FormGroup    
      constructor(private fb: FormBuilder) { }
    
      ngOnInit() {
        this.formGroup = this.fb.group({
          sliders: this.fb.array([])
        })
      }
      get sliderForms() {
        return this.formGroup.get('sliders') as FormArray
      }
    
      clearAll() {
        this.formGroup.reset()
        this.sliderForms.clear()
      }
    

提交回复
热议问题