[Solved] What’s the best way to add/remove dynamically Form Array item?


You should call push method on formArray control. Since you are pushing new FormGroup inside normal array underlaying FormGroup is not get updated.

    addFarina() {
        let farineForm = this.form.value.ingredienti.farine;
        let farineFormControls = this.form.get('ingredienti').get('farine') as FormArray;
    
        if (farineForm.length < 4) {
          const farina = this.fb.group({
            quantita: [null, [Validators.required]],
            nome: ['']
          })
    
          farineFormControls.push(farina);
        }
        console.log(this.form.get('ingredienti').value);
      } 

Now you should be able to access all formValue like this no need to push values inside array manually.

this.api.addRecipe(this.form.value).subscribe(...)

Working Stackblitz

4

solved What’s the best way to add/remove dynamically Form Array item?