I'm building a form similar to this:
private _buildForm(): FormGroup {
const _form = new FormGroup({
title: new FormControl('', [Validators.required]),
jobs: new FormArray([
new FormGroup({
_id: new FormControl(''),
status: new FormControl('')
});
])
});
}
When I want to patch the form using the patchValue() method (for example, when the data comes back from the server), the jobs array is only patched for one element. In other words, if the jobs array contains more than one job, only the first job FormGroup is patched. I thought Angular would be smart enough to dynamically add as many FormGroups as required to match. How else can the job FormGroups be patched?
FormGroupinstances to theFormArrayas you like, but in the above code there is only one. You need to add the logic to add controls to aFormArray.