Search code examples
angularangular4-formsangular-reactive-forms

Submit Only Selected Values in Reactive Forms Inside of FormArray


I believe this is an easy problem but I'm confused on how should i only submit selected values on my submit button like I want that only ingredient_id and price should be appear on the console.log. I'm confused since it is inside of the formArray. Quantity should not appear on console.log? This is my stackblitz CODE

onSubmit(form: FormGroup){
    const Data = {
      values: this.addForm.get('rows').value
    }
    console.log(Data)
  }

Solution

  • There is no automation tool you have to write your own custom output below is an example:

      onSubmit(form: FormGroup){
        let values_ = [];
        this.addForm.get('rows').value.forEach(item => {
          values_.push({
            ingredient_id: item['ingredient_id'],
            unit_price: item['unit_price']
          })
        })
        const Data = {
          values: values_
        }
        console.log(Data)
      }