调用formControl setValue会取消选择芯片列表

时间:2019-05-21 22:14:36

标签: angular angular-material

我有一个mat-chip-list输入字段。筹码为selected风格。我注意到,每当我将setValue()称为字段表单控件时,都会取消选择筹码。有什么办法可以防止这种行为?

之前:enter image description here 之后:m

  <mat-form-field appearance="outline" class="width-100-percent">
    <mat-label>Assigned Entities</mat-label>
    <mat-chip-list #entityChipList>
      <mat-chip selected  *ngFor="let entityId of entityIds; let idx = index"
                           (removed)="removeEntity(idx)">
        {{entityId}}
        <mat-icon matChipRemove>cancel</mat-icon>
      </mat-chip>
      <input #entityInput name="entity" placeholder="Add new entity" formControlName="entityInput"
             [matAutocomplete]="auto"
             [matChipInputFor]="entityChipList"
             [matChipInputSeparatorKeyCodes]="separatorKeyCodes"
             (matChipInputTokenEnd)="add($event)"/>
    </mat-chip-list>
    <mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
      <mat-option *ngFor="let entityInfo of filteredEntityInfos | async" [value]="entityInfo">
        {{entityInfo.entityName}}
      </mat-option>
    </mat-autocomplete>
  </mat-form-field>

0 个答案:

没有答案