【问题标题】:Angular progmatically empty an input with Bootstrap typeaheadAngular 使用 Bootstrap 预输入以编程方式清空输入
【发布时间】:2013-07-23 17:04:31
【问题描述】:

我正在使用表单将元素添加到显示在表单一侧的列表中。标记是:

<form name="stateForm">
  <input type="text" ng-model="model.name" typeahead="state for state in states | filter:$viewValue">
  <button ng-click="addState(model)">Add to list</button>
</form>
<ul>
  <li ng-repeat="state in selected_states">{{state.name}} - {{state.desc}}</li>
</ul>

当控制器是:

  $scope.states = ['Alabama', 'Wyoming'];
  $scope.selected_states = [];
  $scope.addState = function(state){
    $scope.selected_states.push(state);
    $scope.model = {};
    $scope.stateForm.$setPristine();        
  }

工作样本:http://plnkr.co/edit/sLQCCm?p=preview

现在的问题是,虽然我可以使用 $scope.model={}$scope.stateForm.$setPristine() 清除每个输入,但使用预输入无法清除输入。我怀疑这可能是因为 typeahead 指令的实现方式。

有没有一种方法可以在不放弃预先输入的情况下实现这一目标?

【问题讨论】:

    标签: javascript twitter-bootstrap angularjs bootstrap-typeahead


    【解决方案1】:

    实际上,typeahead 指令中有一个错误会阻止您的场景正常工作。它已经在 master 中修复,并将成为下一个版本 (0.5.0) 的一部分,希望在接下来的一周内。

    与此同时,您可以从 CI 服务器获取最新版本,如下图所示: http://plnkr.co/edit/j9undd?p=preview

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多