6

先行入力を使用して、標準の Bootstrap先行入力オプションとして利用できるいくつかのオプションを設定しようとしています。

次のコードを使用すると、「typeahead-min-length」としてインラインで「minLength」プロパティを設定できますが、「typeahead-items」と同じように「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>

更新: jQuery を使用せず、AngularJS のみを使用しようとしています。

これは私のコントローラーです:

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

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

1 に答える 1

7

Typeahead を初期化するために JS の方法を使用してみませんか。

$('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'>
于 2013-07-18T21:58:23.190 に答える