从ui-select中选择两个项目后禁用ui-select-choices,除非用户删除至少一个项目。此代码适用于多选。限制属性不起作用。因此,我使用on-select来提醒用户他们是否选择了2个以上的项目。但要求是限制2并禁用选择。我们怎么做?
<ui-select multiple ng-model="cModel.selectedCountries" ng-disabled="isReadOnly" theme="bootstrap" on-select="someFunction($item, $model)">
<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>
答案 0 :(得分:1)
这就是你在寻找什么
<ui-select multiple limit="2" ng-model="cModel.selectedCountries" ng-disabled="isReadOnly" theme="bootstrap" on-select="someFunction($item, $model)">
<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>