4
votes

I'm trying to do custom validation and I need to add new validators during runtime. This can be accomplished using

control.setValidators([control.validator, newValidator.toValidatorFn])

where control is instance of AbstractControl.

OK, so far all fine and dandy. However, I would like to check if the validator I'm adding has been already added. I also would like to later locate the validator I added to manipulate it further.

So the question is: how can I iterate through the validators that are attached to certain AbstractControl instance?

1

1 Answers

2
votes

That is not possible from what it looks like to me.

Internally, setValidators is adding the validators (which are functions) to a public property on the AbstractControl class named validator.

Inspecting the validator property (with something like console.log(control.validator)) will basically show you the whole validation function that will be run for the control.

You can look and the implementation here if you are interested.