How can we access topmost formControll in a validator function of a nested formgroup?

68 views Asked by At

How can we access the entire form inside a validator function.

i tried giving control.parent.parent ,but its throwing an error.

private unitNumberValidator(hasMdu){
  return (control: AbstractControl)=>{
  let returnVal = null;
//here i want to access entire form 
  console.log(control.parent.parent);

return returnVal;
}
}

how can we achieve this? Thanks

1

There are 1 answers

4
yurzui On BEST ANSWER

Just use root getter like:

<FormGroup>control.root

https://angular.io/api/forms/AbstractControl#root