AngularJS: ui-select once selected not able to remove selected option apart from change option

主宰稳场 提交于 2019-12-07 17:56:46

问题


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?


回答1:


You 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>


来源:https://stackoverflow.com/questions/30750074/angularjs-ui-select-once-selected-not-able-to-remove-selected-option-apart-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!