It's really clear how to set custom errors in angular:
this.form.controls['field'].setErrors({same:true});
But it is not clear on how to remove that. Anyone know how to do this? Any alternatives?
Just set erros to null
this.form.controls['field'].setErrors(null);
this.form.controls['field'].updateValueAndValidity();
this is the method documentation:
/**
* Re-calculates the value and validation status of the control.
*
* By default, it will also update the value and validity of its
ancestors.
*/
updateValueAndValidity({onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {... }
You can use the following when you want to remove the custom error:
delete this.form.controls['field'].errors['same']
you might need/want to update the validity after this with:
this.form.controls['field'].updateValueAndValidity();