ngx-chips:无法从autocompleteItems添加第二个标签

时间:2018-11-11 01:49:22

标签: angular typescript ngx-chips

我正在将ngx-chipsautocompleteItems一起用于标签输入,但是在添加第一个标签之后,下拉列表不再显示,并且console中也没有错误。 / p>

HTML

<tag-input
    [ngModel]="columnsToIgnore"
    [ngModelOptions]="{standalone: true}"
    [placeholder]="'Enter variables to ignore'"
    [secondaryPlaceholder]="'Enter variables to ignore'"
    [onlyFromAutocomplete]="true"
    (onAdd)="addIgnoreColumn($event)"
    (onRemove)="removeIgnoreColumn($event)"
    theme='bootstrap'>
     <tag-input-dropdown
       [autocompleteItems]="selectedDataset.schema.columns"
       [displayBy]="'name'"
       [focusFirstElement]="true">
          <ng-template let-item="item" let-index="index">
            {{ item.name }} : {{ item.type }}
          </ng-template>
     </tag-input-dropdown>
</tag-input>

添加第一个tag时,将显示下拉列表 enter image description here

,但是尝试添加第二个时,不会显示下拉列表 enter image description here

Stackblitz

1 个答案:

答案 0 :(得分:2)

由于您将复杂的object用作options,因此应使用identifyByngx-chips将比较所选项目和提供的选项。

 <tag-input
    [ngModel]="columnsToIgnore"
    [ngModelOptions]="{standalone: true}"
    [placeholder]="'Enter variables to ignore'"
    [secondaryPlaceholder]="'Enter variables to ignore'"
    [onlyFromAutocomplete]="true"
    (onAdd)="addIgnoreColumn($event)"
    (onRemove)="removeIgnoreColumn($event)"
    theme='bootstrap'>
     <tag-input-dropdown
       [autocompleteItems]="selectedDataset.schema.columns"
       [displayBy]="'name'"
       [identifyBy]="'name'" <!-- use any property of object -->
       [focusFirstElement]="true">
          <ng-template let-item="item" let-index="index">
            {{ item.name }} : {{ item.type }}
          </ng-template>
     </tag-input-dropdown>
</tag-input>

工作副本在这里-https://stackblitz.com/edit/angular-icraz4