In a child component I need to get a FormControl
from a parent's FormGroup
. It's easy enough to do by injecting FormGroupDirective
into the constructor and then calling .control.get()
on that injected item.
However, if the form control is actually nested inside of a FormArray
, then that doesn't work. What's the equivalent for getting the FormControl
from the FormArray
?
In my HTML I have just a pretty standard setup
<div [formGroup]="formGroup">
<ngb-accordion formArrayName="subspaces">
<ngb-panel *ngFor="let subspace of subspaces; index as i" [formGroupName]=i">
<my-custom-control controlName="someControlName"
By using the directive I don't have to actually pass in the formGroup
. Ideally I wouldn't have to pass the formArrayName
or formGroupName
to my-custom-control
but I can if I have to.
I'm wanting to avoid passing something like this.formArray.at(index).get('someControlName')
to the child control. I'm wanting to just pass the controlName
and let the child "find" it directly.
I'm not sure how to get the FormArray
instance from the FormGroupDirective