AngularJS: ui-select after selection failed to remove selected option except change option
I am using ui-select to fetch data from the server and populate it in a dropdown (search and select). I have created a plunker for you.
<ui-select ng-model="country.selected" theme="selectize" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select or search a country in the list...">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="country in countries | filter: $select.search">
<span ng-bind-html="country.name | highlight: $select.search"></span>
<small ng-bind-html="country.code | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
Once I have selected any value from the selector, I can change it. But failed to delete. How can i do this?
+3
user4870812
source
to share
1 answer
You have to use a different theme, for example select2
, to make this work. I've updated PLUNKER to show how this might work. Add allow-clear="true"
to ui-select-match
and set theme to theme="select2"
to enable deselection of an item.
<ui-select ng-model="country.selected"
theme="select2"
ng-disabled="disabled">
<ui-select-match allow-clear="true" placeholder="Select country">
{{$select.selected.name}}
</ui-select-match>
<ui-select-choices repeat="country in countries | filter: $select.search">
<span ng-bind-html="country.name | highlight: $select.search"></span>
<small ng-bind-html="country.code | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
+3
source to share