src/app/_helpers/custom-error-state-matcher.ts
Custom provider that defines how form controls behave with regards to displaying error messages.
ErrorStateMatcher
Methods |
isErrorState | ||||||||||||
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null)
|
||||||||||||
Checks whether an invalid input has been made and an error should be made.
Parameters :
Returns :
boolean
true - If an invalid input has been made to the form control. |
import {FormControl, FormGroupDirective, NgForm} from '@angular/forms';
import {ErrorStateMatcher} from '@angular/material/core';
/**
* Custom provider that defines how form controls behave with regards to displaying error messages.
*
* @implements ErrorStateMatcher
*/
export class CustomErrorStateMatcher implements ErrorStateMatcher{
/**
* Checks whether an invalid input has been made and an error should be made.
*
* @param control - Tracks the value and validation status of an individual form control.
* @param form - Binding of an existing FormGroup to a DOM element.
* @returns true - If an invalid input has been made to the form control.
*/
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted: boolean = form && form.submitted;
return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted));
}
}