JavaScript AngularJS - Pagination not rendering on $scope.Watch change (CodePen included)

Question Background:

I'm learning AngularJS. I have created a simple app that takes in 3 form inputs, and on submission of this form a paginated list should be rendered. I have a dependancy on UI-Bootstrap. This is a Plnkr showing the pagination example I'm attempting to incorporate into my app: http://plnkr.co/edit/81fPZxpnOQnIHQgp957q?p=preview

The Issue & Demo:

This is the link to my code so far on CodePen:

http://codepen.io/daveharris/pen/NNMQyy

I have a list of 1000 items populating on my SearchingService model that is injected and shared between the two controllers.

I cannot get the paginated ng-repeat to populate when the searchingService.searchList list on the SearchingService model is changed, It is as if the $scope.Watch is not being triggered.

Any help getting to the bottom of this will be much appreciated.

Answer:1

As bchemy pointed out, $watch should be changed to $watchCollection. But this change won't be enough to have your app working correctly with your current code, since the pagination looks broken.

You should also add another watcher to control the pagination as the one in the example that you want to replicate:

$scope.$watch('currentPage + numPerPage', function() {
    var begin = (($scope.currentPage - 1) * $scope.numPerPage)
    , end = begin + $scope.numPerPage;

    $scope.filteredItems = $scope.searchingService.searchList.slice(begin, end);
  });

Also $scope.items array was getting duplicate searchLists in it and would mess the pagination length.

I have created this Plunker where you can see your example fully working.

Answer:2

I made a table that has checkboxes that show and hide rows to make it easier to compare specific rows. I wanted to add indeterminate checkboxes so that multiple rows can be selected or not selected at ...

I made a table that has checkboxes that show and hide rows to make it easier to compare specific rows. I wanted to add indeterminate checkboxes so that multiple rows can be selected or not selected at ...

I'm trying to crawl a webpage using Nightmare, but want to wait for #someelem to be present, only if it actually exists. Otherwise, I want Nightmare to move on. How can this be done using .wait()? I ...

I'm trying to crawl a webpage using Nightmare, but want to wait for #someelem to be present, only if it actually exists. Otherwise, I want Nightmare to move on. How can this be done using .wait()? I ...

I'm trying to figure out how to trigger a link button to trigger and change all checkboxes to checked when clicked upon. When I click the button, it will bring up the alert message, but not triggering ...

I'm trying to figure out how to trigger a link button to trigger and change all checkboxes to checked when clicked upon. When I click the button, it will bring up the alert message, but not triggering ...

  1. trigger check checkbox jquery
  2. trigger checkbox check
  3. trigger checkbox check event

I am currently working on an problem with a login page for an AngularJS app. The login page uses the $http service to submit the username and password using Basic authentication (Authorization: Basic ...

I am currently working on an problem with a login page for an AngularJS app. The login page uses the $http service to submit the username and password using Basic authentication (Authorization: Basic ...