My example here https://stackblitz.com/edit/angular-unxe7d?file=app%2Finput-error-state-matcher-example.ts
I'm trying to set hasErrors on formControl which I use in matFormField. Like this:
@Component({
selector: 'input-error-state-matcher-example',
template: `<form class="example-form">
<mat-form-field class="example-full-width">
<input matInput
placeholder="Email"
[formControl]="emailFormControl">
</mat-form-field>
{{emailFormControl.hasError('incorrect')}}
{{emailFormControl.valid}}
</form>`,
styleUrls: ['./input-error-state-matcher-example.css'],
})
export class InputErrorStateMatcherExample implements OnInit {
emailFormControl = new FormControl('');
ngOnInit() {
this.emailFormControl.setErrors({ 'incorrect': true });
}
}
But emailFormControl.hasError('incorrect') always false and emailFormControl.valid is true. Is this wrong behavior or I doing something wrong?