我在这里工作的分页
但是我想更改数据以使用我正在创建的 API 数据,但是我遇到了一个错误,我不知道为什么。
这是错误:
TypeError: Cannot read property 'then' of undefined
这是代码:
angular.module('cbuiRouterApp')
.controller('BrowseCtrl', function ($scope, $http, socket) {
$scope.itemData = [];
$http.get('/api/items').success(function(itemData) {
$scope.itemData = recipeData;
socket.syncUpdates('Item', $scope.itemData);
});
$scope.predicate = '-created_at';
$scope.totalItems = $scope.itemData.length;
$scope.itemsPerPage = 21
$scope.currentPage = 1;
$scope.maxSize = 5;
$scope.pageCount = function () {
return Math.ceil($scope.itemData.length / $scope.itemsPerPage);
};
$scope.itemData.$promise.then(function () {
$scope.totalItems = $scope.itemData.length;
$scope.$watch('currentPage + itemsPerPage', function() {
var begin = (($scope.currentPage - 1) * $scope.itemsPerPage),
end = begin + $scope.itemsPerPage;
$scope.filteredItems = $scope.itemData.slice(begin, end);
});
});
});