Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get angular2 formcontrol parent

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.

like image 290
gkarch Avatar asked Sep 07 '16 21:09

gkarch


People also ask

How do I get FormControl values?

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.

What is the difference between FormControlName and FormControl?

[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.


1 Answers

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

like image 153
DDeis Avatar answered Sep 20 '22 04:09

DDeis