Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

454
Views
How to patch value in the dynamic form array Angular

I am using Angular 8 with reactive forms.

On ngOnInit i am calling generateForm and patchDatainForm function simultaneously, and if patchData contain value then i want to push values in formArray.

constructor(private fb: FormBuilder) {
        this.dataCollectionForm = this.fb.group({
            items: this.fb.array([])
        });
    }    
    ngOnInit() {
        this.generateForm();
        this.patchDatainForm();
    }    

    createBatchForm(line, type) {
        return this.fb.group({
            makeLineId: [type.makeLineId],
            processTechType: [type.processTechType],
            avgBct: ['', [Validators.required]],
            bestBct: ['', [Validators.required]],
            avgCapacity: ['']
        });
    }    
    itemTypes(): FormArray {
        return this.dataCollectionForm.get("items") as FormArray;
    }
 generateForm() {        
  this.itemTypes().push(this.createBatchForm('Red', 'Batch'));
}

I have below data from backend to patch the arrays. I want to patch types array in my form fields.

patchDatainForm() {
    const patchData = [{
      makeLineName: 'Red',
      types: [{
        makeLineId: 6,
        processTechType: "batch",
        avgBct: 50,
        bestBct: 200,
        avgCapacity: 40
      },
      {
        makeLineId: 5,
        processTechType: "batch",
        avgBct: 11,
        bestBct: 10,
        avgCapacity: 10
      }]
    }
    ];
    this.dataCollectionForm.patchValue(patchData);
  }

I commonly patch the values with this method this.dataCollectionForm.patchValue(patchData);, but its not working for dynamic form array.

Any help is appreciated. Thanks in Advance

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!