在Bootstrap-UI typeahead中清除模型

时间:2013-08-29 19:27:22

标签: twitter-bootstrap angularjs

我正在使用Bootstrap-UI的typeahead指令,我想在select上清除模型,从而清除typeahead字段(值将存储在别处)。

在我清除模型之​​后,我似乎无法获得预先更新。

我创建了一个显示错误的plnkr:http://plnkr.co/edit/NitVqHyfE3pfSUIhjUZ3?p=preview

2 个答案:

答案 0 :(得分:1)

您使用了错误的型号名称。您使用的模型称为selected而不是selectedBrandInput

  $scope.onBrandSelect = function ($item, $model, $label) {
      $scope.state = $item;        //save it somewhere
      $scope.selected = undefined; //instead of $scope.selectedBrandInput = null;
      if (!$scope.$$phase) {
          $scope.$apply();
      }
      console.log($item)
  }

答案 1 :(得分:-1)

我能找到的最佳解决方案是

$('.typeahead').typeahead('val', myVal);

使用this reference

您可以通过此方法设置空字符串$('。typeahead')。typeahead('val',“”);

这将清空列表。

相关问题