In my Angular 12 app I have this type of hierarchy:
- app.component
-- Parent component with form (reactive)
--- Component that creates the dynamic components
---- Dynamic component
and my formBuilder form looks like this:
form = this.fb.group({
baseLevelControl: ["base control"],
groupOfGroups: [this.fb.group({
innerGroup1: this.fb.group({
dummy1Control1: "control 1 from inner group 1",
dummy1Control2: "control 2 from inner group 1",
}),
innerGroup2: this.fb.group({
dummy2Control1: "control 1 from inner group 2",
dummy2Control2: "control 2 from inner group 2",
}),
})]
});
My dynamic component only needs to know about the groupOfGroups and not the whole form because it will be used in many places with different kinds of forms.
When I set in the dynamic component
<div [formGroup]="innerForm">
I get a seperate independent form that does not communicate with parent form. If I use
<div formGroupName="innerForm">
I get error that formGroupName must be used with a parent formGroup directive
How can I properly bind the groupOfGroups?
I've create this stackblitz project to emulate the issue, any help would be much appreciated