最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 6

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>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论