How to iterate over existing FormControl validators
I am trying to do a spot check and I need to add new validators at runtime. This can be done using
control.setValidators([control.validator, newValidator.toValidatorFn])
where the control is an instance of AbstractControl.
Ok, so far everything is fine and dandy. However, I would like to check if the validator I am adding has been added. I would also like to later find the validator that I added to manipulate it further.
So the question is, how can I iterate over the validators attached to a specific AbstractControl instance?
source to share
This is impossible from what it seems to me.
Internally setValidators
adds validators (which are functions) to the public property of the class AbstractControl
named validator
.
Property validation validator
(with something like console.log(control.validator)
) will basically show you the entire validation function that will be triggered for the control.
You can take a look and implementation here if you are interested.
source to share