my purpose is show an error when the user doesn't put a value. I know that above example doesn't have a lot of sense, but I don't read the error also if the programs must show. the code is this:
<form (ngSubmit)="ricerca()" #formCampiRicerca="ngForm">
<mat-form-field appearance="legacy" class="col-sm-12 col-lg-6 w-100 p-3">
<mat-label>{{ "APPLICATION......" | }}</mat-label>
<input type="text" [(ngModel)]="flux" class="modInput" #flux="ngModel">
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
<ng-container *ngIf="existsFlux()">
...
</ng-container>
</mat-autocomplete>
// here the error doesn't show also it doesn't have a filed
<mat-error>minlength 4</mat-error>
</mat-form-field>
</form>
In my module I import:
CommonModule,
RicercaCircolariRoutingModule,
ReactiveFormsModule,
FormsModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatAutocompleteModule,
MatDialogModule,
The mat-error doesn't show also doesn't have condition. Anyone can help me?I don't read the error message "minlength 4"
I recommend not giving your template variable for the
NgModel
the same name as another property that you use in the template. I would start by changing that name first, then show the error only when needed.If you want a field to be mandatory, you just need to add the
required
attribute to it.