I am struggling to get the Angular Material forms validation work with Angular Template forms. All examples are working with reactive forms only.
I am generating template Angular Material template forms in the following form:
<mat-form-field *ngSwitchCase="'text'" class="entity-form-field" appearance="outline">
<input matInput [placeholder]="field.title" [value]="getValue(field)"
(change)="setValue(field, $event)" [required]="field.req" [id]="field.id">
<mat-error *ngIf="fieldInvalid(field)">{{getErrorMessage(field)}}</mat-error>
</mat-form-field>
Both fieldInvalid and getErrorMessage are working fine, so the field error message should be visible. If I change it to a different tag then it will be visible:
<p *ngIf="fieldInvalid(field)">{{getErrorMessage(field)}}</p>
I understand that the Reative Forms have to change the state of the input to make change it's style to make it visible.
Is there a way to do the same with simple Template Forms? I could probably also apply the Angular Material error styles, but I can't find the documentation.
@Directive. Then it's possible to access the errors via template variables such asname.perstinefor#nameetc.<mat-errors>should work as well doc - WildDev