Angular 仅当输入至少有一个数字时才显示mat自动完成

Angular 仅当输入至少有一个数字时才显示mat自动完成,angular,Angular,今天在我的代码中,当焦点在输入中时,所有选项都被加载。我想使mat autocomplete仅在输入至少有一个数字时可见 我的代码: <mat-form-field> <input type="text" placeholder="{{ 'client' | translate }}" matInput [formControl]="entitySearchCtrl" [(ngModel)]="selectedClientForSearch" [matAutocompl

今天在我的代码中,当焦点在输入中时,所有选项都被加载。我想使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>

{{client.socialName}-{{client.cnpj_cpf}
试试这个:

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

您是否也可以显示TS代码,如果用户输入一个数字然后将其删除,会发生什么情况,是否再次将其隐藏?