I have the following form:
form = this.builder.group({
form2: this.builder.array([
this.builder.group({
name: new FormControl(),
surname: new FormControl(),
})
]),
});
in my oninit I am doing this to set one formcontrol with a setvalue
this.form.controls.personNameField.setValue(this.person.name);
But this does not work, probably due to the controls being inside an formarray. But how can I access my formarray controls?
form.controls['form.someControlName']. And on a different note, you'll want to look intosetValue vs patchValue. Using the former requires you to provide allFormControlsentries in thatFormGroupwhile the latter enables you to patch single values.