ng-selecr中[clearable]的替代品是什么

时间:2019-02-04 05:13:08

标签: javascript angular7 angular-ngselect

我不想使用[clearable]中的ng-select来浪费我的空间。我只想使用[clearable]而不是[clearOnBackspace],但是当我写[clearable] = "false"[clearOnBackspace] = "true"时却不起作用。

enter code here

    <ng-select [items]="cities"
               bindLabel="name"
               placeholder="Select city"
               [(ngModel)]="selectedCity"
               [clearable]="false"
               [clearOnBackspace] = "true"
               [excludeGroupsFromDefaultSelection] = "true">
    </ng-select>

1 个答案:

答案 0 :(得分:0)

如果您执行[clearable]="false",将不允许清除选择。

您可以使用CSS隐藏关闭图标。像这样

.ng-clear-wrapper{
  display: none;
}

并保持ng-select不变

Demo

<ng-select [items]="cities"
               bindLabel="name"
               placeholder="Select city"
               [(ngModel)]="selectedCity"
               [clearable]="true"
               [clearOnBackspace] = "true"
               [excludeGroupsFromDefaultSelection] = "true">

实际上您不需要[clearOnBackspace] = "true"