2017-04-10 71 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