Issue arises from the fact that you are only creating a single FormGroup:
this.selectForm = this.formBuilder.group({
persons: this.formBuilder.array([
this.formBuilder.group({
'person': '',
'country': ''
})
])
})
To resolve this, you should iterate through this.parts
to dynamically generate them:
const persons = <FormArray>this.selectForm.get('persons');
this.parts.forEach((part) => {
part.persons.forEach((person) => {
persons.push(this.formBuilder.group({country: null, name: person.name}));
})
});
This approach will result in two instances of FormGroup
, each containing properties for country
and name
. It offers a more direct method than your current solution, making the code cleaner. Ensure to update the template accordingly.