仅在输入至少有一位数时显示mat-autocomplete

时间:2017-12-27 19:42:59

标签: angular

今天在我的代码中,当焦点在输入中时,所有选项都被加载。我想只在输入至少有一位数字时才能看到 mat-autocomplete

我的代码:

<mat-form-field>
    <input type="text" placeholder="{{ 'client' | translate }}" matInput [formControl]="entitySearchCtrl" [(ngModel)]="selectedClientForSearch" [matAutocomplete]="auto">
    <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
      <mat-option *ngFor="let client of relatedClients | async" [value]="client">
        {{ client.socialName }} - {{ client.cnpj_cpf }}
      </mat-option>
    </mat-autocomplete>
  </mat-form-field>

1 个答案:

答案 0 :(得分:0)

试试这个:

 <mat-autocomplete *ngIf="selectedClientForSearch?.length >= 1" #auto="matAutocomplete" [displayWith]="displayFn">

或者:

<input type="text" placeholder="{{ 'client' | translate }}" matInput [formControl]="entitySearchCtrl" [(ngModel)]="selectedClientForSearch" [matAutocomplete]="selectedClientForSearch?.length >= 1 ? auto : null">