angularjs - 如何以编程方式清除 ui-select?

标签 angularjs ui-select

我想找到一种方法,通过代码清除 ui-select 的选择。

例如我有以下代码

<ui-select ng-model="selectedCustomerCode" ng-if="CustomerIds.length>1" on-select="CustomerCodeFiltersOnSelectCallback($item, $model)" theme="bootstrap">
  <ui-select-match class="ui-select-match" allow-clear="true" placeholder="Επιλογή κωδικού πελάτη...">{{$select.selected.CCode}}</ui-select-match>
  <ui-select-choices class="ui-select-choices" repeat="customer in CustomerIds | propsFilter: {CCode: $select.search}">
    <div ng-bind-html="customer.CCode | highlight: $select.search"></div>
  </ui-select-choices>
</ui-select>

我想点击一个清除按钮并清除一些输入,包括 ui-select。 清除ui-select的代码是什么?

最佳答案

问题已解决。 我不知道为什么,但是在 ng-model 中只有 selectedCustomerCode 不能正常工作。 我将 selectedCustomerCode 分配为对象:

ng-model="selectedCustomer.selectedCustomerCode"

然后我能够像这样清除它:

selectedCustomer.selectedCustomerCode = ''

如果我有

ng-model="selectedCustomerCode"

然后将其重新分配给:

selectedCustomerCode = ''

不知何故不起作用。

关于angularjs - 如何以编程方式清除 ui-select?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41423987/

相关文章:

angularjs - 我可以从指令内部观察 Controller 范围属性吗?

javascript - 使用 Angular 如何不反对代码分离?

python - Angular $routeProvider 不解析 django 变量

html - ui-grid 删除排序菜单并将列标题对齐到最右侧

javascript - AngularJs - 制作漂亮的选择下拉框(不使用图像)

ng-class 无法正确选择 UI

javascript - 当 ui-select 标记为必需时,如何重置 Angularjs ui-select 组件所有选择而不显示红色错误突出显示

javascript - Angular,将信息从 2 个不同的模块提取到一个(或单独的模块)中