Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Clear form control errors

How to clear the errors on form control. I have a method that tries to clear the errors on the form control but in vain.

this.form.controls[ 'postalCode' ].setErrors(null);

The form control name is postalCode and when I set the error to null, it doesn't remove the error from that control.

like image 318
Karthikeyan Mohan Avatar asked Nov 27 '22 01:11

Karthikeyan Mohan


1 Answers

To clear all the errors

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

To clear by its key

this.form.get('postalCode').setErrors({key: null});
this.form.get('postalCode').updateValueAndValidity(); //may need this in child components
like image 173
Hary Avatar answered Nov 28 '22 14:11

Hary