0

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"
    },
....
]}
Community
  • 1
  • 1
Russell
  • 655
  • 2
  • 9
  • 21
  • 1
    [MCVE](http://stackoverflow.com/help/mcve) is necessary. Please, provide a plunk or a fiddle if you can't debug the app by yourself. But the code above will result in error because `myData` is initially undefined. I guess you haven't checked the console for errors, so this is the first thing you can do. – Estus Flask Dec 23 '16 at 15:26
  • $scope.myData = response.data.records; – dimson d Dec 23 '16 at 18:54

0 Answers0