I am looking to develop a shared component for displaying errors in Angular Material.
Here is my shared component pfa-share-error
:
<mat-error *ngIf="fieldErrors(fieldName).required && fieldErrors(fieldName)">
Required
</mat-error>
<mat-error *ngIf="fieldErrors(fieldName).touched && fieldErrors(fieldName)">
Required
</mat-error>
<mat-error *ngIf="fieldErrors(fieldName).pattern && fieldErrors(fieldName)">
Required
</mat-error>
And I am using this in my form:
<mat-form-field appearance="outline">
<mat-label>{{ "COUNTEY.NAME" | translate }}</mat-label>
<input formControlName="name" matInput />
<pfa-share-error [form]="addCountryFG" field="name"></pfa-share-error>
</mat-form-field>
However, when an error occurs, it displays like this in my form: https://i.stack.imgur.com/UwaGH.png
I want the error messages to appear like this instead:
https://i.stack.imgur.com/1wj8i.png
How can I solve this problem now?