我正在尝试使用Angular UI typeahead。我的问题是下拉列表没有显示。正确调用远程数据并返回数据......但是下拉列表拒绝显示...
<td colspan="5">
<pre>Model: {{selected| json}}</pre>
<input id="AutoCompleteDebtor"
type="text"
data-ng-model="selected"
data-typeahead="debtor for debtor in Debtors($viewValue)"
class="form-control input-sm"
placeholder="Enter 3 letters of Debtor Name" />
</td>
更新:好的 - 它与字符串名称数组配合良好,但我如何使用对象?
<!DOCTYPE html>
<html data-ng-app="myApp">
<head>
<title>Angular Typeahead</title>
<link href="Content/bootstrap/bootstrap.min.css" rel="stylesheet" />
<script src="Scripts/angular.min.js"></script>
<script src="Scripts/ui-bootstrap-tpls-0.6.0.min.js"></script>
<script>
angular.module('myApp', ['ui.bootstrap'])
.controller('SimpleController', function ($scope) {
$scope.people = [
{ name: 'Alan', age: 23 },
{ name: 'Bruce', age: 24 },
{ name: 'Celine', age: 53 },
{ name: 'Dan', age: 43 },
{ name: 'Eric', age: 23 },
{ name: 'Freda', age: 47 },
{ name: 'Greg', age: 73 },
{ name: 'Hanna', age: 27 }
];
});
</script>
</head>
<body data-ng-controller="SimpleController">
<div>
<pre>Model: {{selected| json}}</pre>
<input type="text" data-ng-model="selected" data-typeahead="name for name in people | filter:$viewValue | limitTo:8">
</div>
</body>
</html>
我一直在关注https://github.com/angular-ui/bootstrap/tree/master/src/typeahead示例
答案 0 :(得分:1)
我找到了这个小提琴的答案:http://jsfiddle.net/ukAc5/1/
data-typeahead="n.name for n in people
答案 1 :(得分:0)
我从格雷格的回答中解决了我的先行模式。这就是我为我的预先做的事情(希望这有助于某人):
typeahead="i.t_UserName for i in employeeInfo | filter:$viewValue | limitTo:4"
作为html输入的属性
并在您的控制器中(使用员工资源)
$scope.employeeInfo = getEmployeeResourceSvc.getEmplInfo.query(function(response){
$scope.employeeInfo= response;
});