I have a reactive form and I want to show different error messages with <mat-error>, but I don't know how. I searched already a bit.
TS:
selectDataFormGroup: FormGroup = this.formBuilder.group({
headerCoordinate: ['', [
Validators.required,
Validators.pattern(/^.+:.+$/)
]
],
contentCoordinate: ['', [
Validators.required,
Validators.pattern(/^.+:.+$/)
]
],
});
HTML:
<mat-form-field fxFlex>
<input matInput formControlName="headerCoordinate">
<mat-error>{{ 'Field is required' | translate }}</mat-error>
</mat-form-field>
I need different error messages for required and pattern. <mat-error> shows up when the form field is not valid in general. How can I achieve this?