我使用ui-select从服务器获取数据&填充在下拉菜单中(搜索&选择)。我为你创建了一个活塞。
<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>
一旦我从选择器中选择了任何值,我可以进一步更改。但无法移除。我该怎么做呢?
您应该使用其他主题,如select2
来完成此工作。我升级了你的PLUNKER来展示它是如何工作的。将allow-clear="true"
添加到ui-select-match
中,并将主题设置为theme="select2"
,允许不选择项目。
<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>