2017-04-10 106 views
0

我正在使用ui选择角。我需要一个选择空值的选项。谷歌搜索,但无法找到适合的解决方案。ui选择角需要一个空值的可选选项

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<ui-select allow-clear ng-model="hotelsCtrl.companySelectedInsert" theme="bootstrap"> 
 
       <ui-select-match placeholder="Select or search company in the list...">{{$select.selected.name}}</ui-select-match> 
 
       <ui-select-choices repeat="company in hotelsCtrl.companies | filter: $select.search"> 
 
        <span ng-bind-html="company.name | highlight: $select.search"></span> 
 
       </ui-select-choices> 
 
      </ui-select>

having this

回答

-1

的直截了当的办法就是用空值在hotelsCtrl.companies将其设置为ui-select前添加和元素。

是这样的:

{ 
     name:'none', 
     value:null 
    } 

也许如果你想只是选项之一重置一次被选中,然后用退格键

这里是一个工作的例子,看看这个http://jsfiddle.net/Miqe/x6bqubtw

+0

公司= [{name:'none',value:null}]; 我将此添加到我的酒店按钮。但仍然不起作用。 – Senpuki

+0

向我展示来自'hotelsCtrl.companies'数组的一个样本元素 – Miqe

+0

该数组为空。我从数据库中获得我的公司。 – Senpuki