0

Good day guys, please I am having issues updating values in a formArray from my angular 6 component. I have tried using setValue() and patchValue() no one of them is working. Below is my code

 this.form = this._formBuilder.group({
       locationRequests: this._formBuilder.array([
          this._formBuilder.group({
          location: '',
          item_category: '',
          items: '',
          quantity: '',
          packaging: '',
          unit_of_measurement: '',
    });
        ])
    });

I want to set value to each of the fields from my component, i have tried

this.form.patchValue({
 locationRequests: this._formBuilder.array([
          this._formBuilder.group({
          location: 'New York',
          item_category: 2,
          items: 1,
          quantity: 500,
          packaging: 1,
          unit_of_measurement: 'PCS',
}
});

I have also tried using setValue function still did not work. I have searched online and all the answers aren't working.

0

1 Answer 1

2

while patching use this.

this.form.patchValue({ locationRequests: [ { location: 'New York', item_category: 2, items: 1, quantity: 500, packaging: 1, unit_of_measurement: 'PCS', }] });

You don't need to specify this._formBuilder.group or this._formBuilder.array while patching values.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much @sachinGupta for this answer, I have been battling with this for the past 24 hours. I just tried your code and it worked very well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.