I'm trying to nest several FormGroups, which works very well if I do not want to outsource the template to own components.
Here is an example, that works
Template
<form [formGroup]="baseForm">
<div formGroupName="nestedForm1">
<div formGroupName="nestedForm2">
<input formControlName="nestedControl">
</div>
</div>
</form>
Typescript
this.baseForm = this.formBuilder.group({
nestedForm1: this.formBuilder.group({
nestedForm2: this.formBuilder.group({
nestedControl: ["Default Value"]
})
})
});
If I try to outsource the "nestedForm1" and "nestedForm2" into a separate component, it does not work anymore from the second level.
An example can be found at the following link. There you can try both ways by commenting out the respective code parts in the "app.component.html"
https://stackblitz.com/edit/angular-gnpw24?file=src%2Fapp%2Fapp.component.html