【问题标题】:Setting options for typeahead, using Angular-ui Bootstrap使用 Angular-ui Bootstrap 设置预输入选项
【发布时间】:2013-07-19 08:37:14
【问题描述】:

使用 typeahead,我正在尝试设置几个选项,它们可作为标准 Bootstrap typeahead options

使用下面的代码,我可以将“minLength”属性设置为“typeahead-min-length”,但将“items”设置为“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; 
      });
  });

【问题讨论】:

    标签: angularjs typeahead angular-ui-bootstrap


    【解决方案1】:

    为什么不用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'>
    

    【讨论】:

    猜你喜欢
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多