See how to use a form with a custom ErrorStateMatcher
(, , ), errorStateMatcher matInput. ErrorStateMatcher. ErrorStateMatcher isErrorState, FormControl matInput, , , . (true , , false , .)
, default.error-matcher.ts
export class MyErrorStateMatcher implements ErrorStateMatcher {
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
return !!(control && control.invalid && (control.dirty || control.touched));
}
}
TS :
matcher = new MyErrorStateMatcher();
matcher:
<mat-form-field>
<input matInput placeholder="Due Date" name="dueDate" [(ngModel)]="dueDate" [formControl]="dueDateValidator" [errorStateMatcher]="matcher" required>
<mat-error *ngIf="dueDateValidator.invalid">Due Date is required for Tasks</mat-error>
</mat-form-field>