-1

所以,我有一个组合框,用户可以在其中输入。我想要实现的是在用户键入不在组合框选择/选项中的内容时发出警告。这是我的组合框的代码:

<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>

这是组合框。 如您所见,用户可以在组合框中键入,并且只要用户输入不在选择中的代码,它就会警告用户

4

1 回答 1

0
          <input
              type="text"
              #input
              placeholder="Aircraft Type (ICAO)"
              aria-label="Aircraft Type (ICAO)"
              matInput
              (keyup)="check(input.value)"
              formControlName="aircraftType"
              [matAutocomplete]="type"
              (input)="onAircraftTypeChange()"
            />



           check(value:string):void
           {
                  let status = false;
                  filteredAircraftTypes.map(x=>{ 
                  if(x.label===value)status=true})
                  if(!status)
                  {
                     enter code here
                  }


           }
于 2021-09-03T09:20:16.283 回答