0

I have a formBuilder array and a need change his value.

i tried setvalue, but just change the visual.
stackblitz

updateAddress(i,address) {
    // (<FormControl>this.form.controls['adresses'][i].controls.estado).setValue('RR');
    address.value.states = 'GOIAS'
  }

  initializeFormEmpty() {
    this.form = this.formBuilder.group({
      adresses: this.formBuilder.array([this.addressItem()])
    })
  }
  addressItem(): FormGroup {
    return this.formBuilder.group({
      zip_code: this.formBuilder.control('', [Validators.required]),
      states: this.formBuilder.control('RORAIMA', [Validators.required]),
    })
  }

stackblitz

1 Answer 1

2

Change your updateAddress function to the following:

  updateAddress(i,address) {
    let myFormArray = this.form.get('adresses') as FormArray;
    myFormArray.controls[i].get('states').setValue('GOIAS');
  }

Here's a working example of what I believe you are trying to accomplish.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.