So, I have a combo box where the user can type into it. What I want to achieve is to give a warning whenever the user typed something that is not in the combo box selection/option.
Here is the code for my combo box:
<mat-form-field appearance="outline" class="width-1">
<mat-label>Aircraft Type (ICAO)</mat-label>
<!-- test autocomplete aircraft type -->
<input
type="text"
placeholder="Aircraft Type (ICAO)"
aria-label="Aircraft Type (ICAO)"
matInput
formControlName="aircraftType"
[matAutocomplete]="type"
(input)="onAircraftTypeChange()"
/>
<span matSuffix class="down">
<mat-icon>arrow_drop_down</mat-icon>
</span>
<mat-autocomplete
#type="matAutocomplete"
(optionSelected)="onSelectAircraftType($event.option.value)"
[displayWith]="displayAircraftTypeFn"
>
<mat-option
*ngFor="let type of filteredAircraftTypes | async"
[value]="type"
>
{{ type.label }}
</mat-option>
</mat-autocomplete>
<!-- end test autocomplete -->
</mat-form-field>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…