Search code examples
javascriptangular7angular-ngselect

What is the alternative of [clearable] in ng-select


I do not want to use the [clearable] in ng-select for leakage of my space. Instead of [clearable] I want to use only [clearOnBackspace] but when I write [clearable] = "false" and [clearOnBackspace] = "true" it does not work.

enter code here

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

Solution

  • If you do [clearable]="false" it will disallow to clear the selection.

    you can use css to hide the close icon. like this

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

    and keep ng-select as it is

    Demo

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

    infact you do not need [clearOnBackspace] = "true"