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

I am using ui-select for fetching data from server & populate it in drop down (search & select)

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742263328a4411316.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信