ui-select with single select(限制属性不起作用)

时间:2016-03-21 16:23:53

标签: jquery angularjs angular-ui angular-ui-select

这是我的代码。我使用了角度UI选择。它工作得很好。但是现在,要求更改了下拉列表只需选择一次。我使用了limit属性,但它不起作用。

<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>

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分: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();
}