这是情况,我有以下内容: - 一个输入字段,我在其中输入带有 ng-model='user_name' 的用户名。- 一个带有 ng-click="queryUserLogs(user_name, $event) 的按钮 - 当我输入用户名并单击该按钮时,将调用在我的控制器中定义的以下方法:
// un: username
$scope.queryUserLogs = function(un, $event){
if(typeof $scope.user_name !== 'undefined'){
var transaction_id = gen_uuid();
$scope.$watch("user_name", function (newVal, oldVal) {
if($event.type === "click"){
console.log("Reloading...");
$scope.tableParams.reload();
delete $event.type;
}
});
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10, // count per page
}, {
total: 0,
getData: function($defer, params) {
BI.get({userName: $scope.user_name, page: params.page(), count: params.count()}, function(data) {
// set new data
$scope.basicInfos = data.results;
params.total(data.count);
$scope.showLogs = true;
$defer.resolve(data.results.slice((params.page() - 1) * params.count(), params.page() * params.count()));
});
},
$scope: { $data: {} }
});
} else {
console.log("Username is empty!");
}
}
- 对于第一个请求,该方法被正常调用,使用 BI $resource 进入服务器并获取数据并正确显示。一切正常。
当我更改用户名并单击按钮时,控制台中会出现以下错误:
TypeError: undefined is not a function at http://localhost:8000/static/js/ng-table.min.js:414:33 at u (http://localhost:8000/static/js/angular.min.js:97:280) at http://localhost:8000/static/js/angular.min.js:98:417 at h.$eval (http://localhost:8000/static/js/angular.min.js:108:482) at h.$digest (http://localhost:8000/static/js/angular.min.js:106:62) at h.$apply (http://localhost:8000/static/js/angular.min.js:109:287) at f (http://localhost:8000/static/js/angular.min.js:71:247) at F (http://localhost:8000/static/js/angular.min.js:75:408) at XMLHttpRequest.x.onreadystatechange (http://localhost:8000/static/js/angular.min.js:76:457)
新数据实际上检索成功,但分页停止工作,如果第一个查询的用户名有 4 页,而第二个只有一页,则分页在第二个查询中保持为 4 页,反之亦然。
PS: ngTable 被添加到控制器依赖项中。