[英]Setting options for typeahead, using Angular-ui Bootstrap
使用typeahead,我試圖設置幾個選項,它們可用作標准的Bootstrap typeahead選項
使用下面的代碼,我可以通過將其設置為“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'>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.