角垫自动完成位置未更新

时间:2020-04-23 09:20:09

标签: angular angular-material mat-autocomplete

我正在使用变量切换mat-autocomplete的位置:

  <mat-form-field class="dialerFormField">
    <input
      type="text" matInput[formControl]="myTextControl"
      [matAutocomplete]="auto"
      #autoCompleteInput
    />
    <mat-autocomplete #auto="matAutocomplete">
      <mat-optgroup
        *ngFor="let group of usersGroup"
        [label]="group.type"
      >
        <mat-option *ngFor="let user of group.users" [value]="user.number">
          {{ user.name }}
        </mat-option>
      </mat-optgroup>
    </mat-autocomplete>
  </mat-form-field>


@ViewChild('autoCompleteInput', {
  read: MatAutocompleteTrigger,
  static: true,
})
autoComplete: MatAutocompleteTrigger;

if (this.clickedOnExtDialpad) {
  this.autoComplete.position = 'above';
} else {
  this.autoComplete.position = 'below';
}

首先执行if-else条件时,无论设置什么位置,自动完成面板都仅在该位置打开,并且在执行if-else条件时以后不更新。

为什么职位不更新?

0 个答案:

没有答案