I am using ui-select for fetching data from server & populate it in drop down (search & select). I 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 selected any value from selector, I can change further. But not able to remove. How can I do this?
I am using ui-select for fetching data from server & populate it in drop down (search & select). I 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 selected any value from selector, I can change further. But not able to remove. How can I do this?
Share edited Feb 18, 2016 at 5:15 Venugopal 1,8961 gold badge17 silver badges30 bronze badges asked Jun 10, 2015 at 7:40 user4870812user4870812 4-
'Not able to remove' remove what? The selected from the
select
? Or from the displayed selected item? – devqon Commented Jun 10, 2015 at 7:52 - @devqon selected from the select – user4870812 Commented Jun 10, 2015 at 7:54
- I wanted to set back like no option selected – user4870812 Commented Jun 10, 2015 at 7:56
-
Then just reset
country.selected
?<button ng-click="country.selected = null">Remove</button>
– devqon Commented Jun 10, 2015 at 7:58
1 Answer
Reset to default 6You should use an other theme like select2
to make this work. I upgraded your PLUNKER to show how this could work. Add allow-clear="true"
into ui-select-match
and set theme to theme="select2"
to allow unselect 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>