gpt4 book ai didi

angularjs - 使用 Angular-ui Bootstrap 设置预输入选项

转载 作者:行者123 更新时间:2023-12-02 03:28:09 25 4
gpt4 key购买 nike

使用 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

这是我的 Controller :

  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 - 使用 Angular-ui Bootstrap 设置预输入选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17734270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com