当ui-select处于禁用状态时如何清除字段?

时间:2016-09-29 15:17:28

标签: javascript jquery angularjs angularjs-directive ui-select

您能否告诉我如何清除该字段或删除处于禁用状态的字段?我在这个例子中使用UI-select。每当用户选择Nicole时,我将添加一个条件,它将取消选择ui-select(用户无法再选择选项)。但我希望用户能够在禁用模式下清除/删除Nicole

示例:如果用户错误地选择Nicole选项,则他无法选择任何其他选项。那么我可以在禁用状态中清除Nicole选项吗?

Here is my plunker.

$scope.OnClickSelect = function(item) {
    if (item.name === 'Nicole') {
      if ($scope.multipleDemo.length > 0) {
        $scope.multipleDemo.pop =[];
      }
      $scope.disabled = true;
    }
    $scope.multipleDemo.push(item.age);
  }

1 个答案:

答案 0 :(得分:0)

问题不明确。即使在选择" Nicole"之后,你想启用ui-select吗?或者只是想清除ng模型?

如果您想在用户意外选择" Nicole"时选择启用ui-select。你必须保留一个复选框或任何设置$scope.disabled = false;

的触发器

OnClickSelect方法还有2个问题。

我猜你正试图在用户选择" Nicole"时清除ng-moodel。但是$scope.multipleDemo.pop =[];为数组multipleDemo创建了一个名为pop的新属性。如果要清除数组,请使用$scope.multipleDemo =[];

为什么要将age属性推入multipleDemo数组?如果只想存储age属性,可以在ui-select代码中使用以下语法

 <ui-select-choices  repeat="person.age as person in people | filter:$select.search">
      {{person.name}}
    </ui-select-choices>