好的,这是今天学习 Angular 三部曲的最后一个问题:
我遇到以下错误(尝试在视图中选择用户时:
TypeError: object is not a function
at Object.source (http://localhost:3000/assets/angular.js?body=1:6300:13)
at getMatchesAsync (http://localhost:3000/assets/angular-ui-bootstrap.js?body=1:1820:30)
at http://localhost:3000/assets/angular-ui-bootstrap.js?body=1:1871:13
at http://localhost:3000/assets/angular.js?body=1:12030:15
at Array.forEach (native)
at forEach (http://localhost:3000/assets/angular.js?body=1:134:11)
at $setViewValue (http://localhost:3000/assets/angular.js?body=1:12029:5)
at http://localhost:3000/assets/angular.js?body=1:11423:14
at Object.Scope.$eval (http://localhost:3000/assets/angular.js?body=1:7994:28)
at Object.Scope.$apply (http://localhost:3000/assets/angular.js?body=1:8074:23) angular.js?body=1:5688
(anonymous function) angular.js?body=1:5688
(anonymous function) angular.js?body=1:4785
Scope.$apply angular.js?body=1:8076
listener angular.js?body=1:11422
jQuery.event.dispatch jquery.js?body=1:5096
elemData.handle
使用此代码(根据 SO 答案更新:
<div ng-app='users'>
<div class='container-fluid' ng-controller="UsersIndexCtrl">
<pre>Model: {{result | json}}</pre>
<input type="text" ng-model="result" typeahead="suggestion for suggestion in users($viewValue)">
</div>
<script>
var app = angular.module('users', ['ui.bootstrap', 'ngResource']);
app.factory('User', function($resource) {
return $resource("users/:id", { id: '@id' }, {
index: { method: 'GET', isArray: true, responseType: 'json' },
show: { method: 'GET', responseType: 'json' },
update: { method: 'PUT', responseType: 'json' }
});
})
var UsersIndexCtrl = function($scope, User) {
$scope.users = User.index();
};
</script>
我正在尝试使用 typeahead 从服务器获取所有用户。
最新版本的 plunker 代码在 这里
问题: 1. 如何从服务器获取集合数据并使用 Angular 运行 typeahead 并修改此代码?2. 这个错误是什么意思以及它是如何导致与此代码相关的。