How to get parent form group in a nested form group for a control. At the time of validation of a control, i need a sibling control value. Both these controls are part of formgroup, which is part of formArray. I know we have root, which gives the root element. How can I get immediate parent of a given form control.
Get and Set Value To fetch the value of a form control, we have to use value property on the instance of FormControl in our class. In the same way we can fetch the value in HTML template. city = new FormControl('Noida'); console. log(this.
[formControl] assigns a reference to the FormControl instance you created to the FormControlDirective . formControlName assigns a string for the forms module to look up the control by name.
You can access the parent of a given FormControl
with .parent
the same way you would be using .root
.
Here's the doc: https://angular.io/api/forms/AbstractControl#parent
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With