angularjs – 使用Angular-ui Bootstrap设置typeahead的选项

前端之家收集整理的这篇文章主要介绍了angularjs – 使用Angular-ui Bootstrap设置typeahead的选项前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用typeahead,我试图设置几个选项,可用作标准的Bootstrap typeahead options

使用下面的代码,我可以通过将其设置为“typeahead-min-length”来设置“minLength”属性,但是对“item”作为“typeahead-items”执行相同操作则不行.有没有不同/更好/标准的方法来做到这一点?有没有办法将一系列选项附加到$scope?

<div class='container-fluid' ng-controller="TestController">

<input type="text" ng-model="selected" 
typeahead="foo for foo in foo | filter:$viewValue" typeahead-items='5' typeahead-min-length='3'>

<pre>{{selected| json}}</pre>  </div>

更新:我试图坚持使用AngularJS,而不是使用jQuery

这是我的控制器:

myAppModule.controller('TestController',function($http,$scope) {
  $scope.selected = undefined;

  $http.get('data/sample.json')
       .then(function(results){
          $scope.foo = results.data; 
      });
  });

解决方法

为什么不使用JS方式初始化typeahead:

$('input.typeahead').typeahead({
    source: array_of_value_here,minLength: 1,items: 5,// your option values ...
});

编辑:

我看,AngularJS方式,你可以使用limitTo:

<input type="text" ng-model="selected" typeahead="foo for foo in foo | filter:$viewValue | limitTo:5" typeahead-min-length='3'>

猜你在找的Angularjs相关文章