Angular: Manually update a model from inside its custom validator avoiding loops

Angular: Manually update a model from inside its custom validator avoiding loops


I know, it could sound weird, in another post I will give more details about this need of mine.

Now I want to focus on the problem:
If you update a model inside its own custom validator, it will trigger the validator again in a devastaing loop.
I was looking for a way to update the model without to trigger the validator, so I played with the parameters of the two methods setValue and patchValue, but it did not work.

In the end, I decided to:

  1. validator to null
  2. update the value
  3. set the validator again.

It works well.

Does someone know a better way to achieve the result?

Leave a Reply

Your email address will not be published. Required fields are marked *