0

Currently I'm trying to create a dynamic validation in Angular Forms and I found this Question.

Adding the error to the field

this.form.get('field').setErrors({ 'invalid': true });

Removing the error to the field

this.form.get('field').setErrors(null);

My question is how can I remove a specific error in the field? Example I have multiple setErrors and I only want to remove the invalid error

Elohist
  • 57
  • 8
  • I'm afraid that you can not, setError replace all the errors. You can always use `setErrors(Validators.required)` or to have an array of errors `[Validators.required,Validators.minLenght(3)]` and use `setErrors(errorsArray)` but I suppose it's not you want – Eliseo Jun 24 '20 at 06:47

1 Answers1

0

I believe this should work:

this.form.get('field').setError({'invalid': null})
  • Hi Ana it does not work. The invalid error is set to null, but the field detect that their is an error. I want to remove only an specific error because when I use the `setError(null)` even the `required` validation is removed. – Elohist Jun 24 '20 at 02:46