2016-03-21 53 views
0

這是我的代碼。我使用了角度UI選擇。它運作良好。但是現在,只有一次選擇下拉菜單的需求發生了變化。我使用限制屬性,但它不工作。ui選擇與單選(限制屬性不起作用)

<span id="oCountriesSpan" ng-class="{'has-error': noCountriesSelected()}"> 
          <ui-select multiple limit="1" ng-model="countryModel.selectedCountries" ng-disabled="isReadOnly" theme="bootstrap"> 
           <ui-select-match placeholder="Select ..." allow-clear="true">{{$item.name}} 
           </ui-select-match> 
           <ui-select-choices repeat="country.id as country in countryCodes | filter:$select.search"> 
            {{ country.name }} 
           </ui-select-choices> 
          </ui-select> 
         </span> 
+0

有沒有其他的辦法限制選擇只有一個? – tv3free

回答

0

限制是在0.13版本之後引入的。我用的是0.12

0

使用下面的代碼來清除選中的選項值

HTML代碼

<ui-select-match placeholder=」Enter table…」> 
<span>{{$select.selected.description || $select.search}}</span> 
<a class=」btn btn-xs btn-link pull-right」 ng-click=」clear($event, $select)」><i class=」glyphicon glyphicon-remove」></i></a> 
</ui-select-match> 

控制器動作代碼

function clear($event, $select){ 
//stops click event bubbling 
$event.stopPropagation(); 
//to allow empty field, in order to force a selection remove the following line 
$select.selected = undefined; 
//reset search query 
$select.search = undefined; 
//focus and open dropdown 
$select.activate(); 
}