ts
formControl = new FormControl('', [
Validators.required, Validators.pattern(/^[a-zA-Z_-]$/),
Validators.minLength(5), Validators.maxLength(32)
]);
errorMessage(): any {
if (this.formControl.hasError('required')) {
return 'You must enter a value';
} else if (this.formControl.hasError('pattern')) {
return 'Username can only be letters,underscores and horizontal lines';
}
}
html
<mat-error>{{errorMessage()}}</mat-error>
this.formControl.hasError('required')It's worksthis.formControl.hasError('pattern')It isn't works
I checked the angular-material document, but did not find the usage. Why does it produce such a result?