I am following the accepted answer to this question about paging in Angular JS. When I put the example on my site it works. But when I try to change the data in the scope to my JSON formatted data it no longer works.
myData.length
gives the correct count, but filteredmyData
ends up just being an empty array
I'm not sure what I need to investigate next. Any help appreciated.
App and controller
var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myCtrl', function($scope, $http) {
$http.get("resource-database.json").then(function (response) {
$scope.myData = response.data.records;
});
$scope.filteredmyData = []
,$scope.currentPage = 1
,$scope.numPerPage = 3
,$scope.maxSize = 5;
$scope.$watch('currentPage + numPerPage', function() {
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;
$scope.filteredmyData = $scope.myData.slice(begin, end);
});
});
resource-database.json
{"records": [
{
"id":"8",
"resource_name":"title of resource",
"resource_source":"web address"
},
....
]}