【发布时间】:2015-03-17 21:44:59
【问题描述】:
我是 angularjs 世界中的一只新蜜蜂。我试图在我的代码中使用一些分页逻辑。
在使用 $watch 时,我的应用在 $watch 上抛出 TypeError: undefined is not a function
.controller("EmployeeListCtrl", ["employeeResource", EmployeeListCtrl]);
function EmployeeListCtrl(employeeResource) {
var Empdata = this;
Empdata.employeePerPage = [];
employeeResource.query(function(data){
Empdata.employee = data;
});
Empdata.currentPage = 1;
Empdata.numPerPage = 10;
Empdata.maxSize = 5;
Empdata.numPages = function() {
return Math.ceil(Empdata.employee.length / Empdata.numPerPage);
};
Empdata.$watch('Empdata.currentPage + Empdata.numPerPage', function() {
var start = ((Empdata.currentPage - 1) * Empdata.numPerPage),
end = start + Empdata.numPerPage;
Empdata.employeePerPage = Empdata.employee.slice(begin, end);
});
}
因为我使用的是 controller as,所以我没有使用 $scope,也许是这样吧?
对于使用 $scope 与 controller as 有什么意见吗? 既然我们在这个 什么是推荐 $scope 或控制器为
【问题讨论】:
标签: angularjs