Commit 505d9b3a447747a4f392822bfc9aaccda32df445

Authored by Leonardo Merlin
1 parent b2c4ee67

Fix: pagination does not update

src/app/components/app-paginator/app-paginator.directive.js
... ... @@ -9,12 +9,14 @@
9 9 function appPaginator() {
10 10  
11 11 /** @ngInject */
12   - function AppPaginatorController($log) {
  12 + function AppPaginatorController($scope, $log) {
13 13 var vm = this;
14 14  
  15 + vm.$scope = $scope;
15 16 vm.$log = $log;
16 17  
17 18 vm.init();
  19 + vm.attachListeners();
18 20  
19 21 $log.debug('AppPaginatorController');
20 22 }
... ... @@ -26,6 +28,12 @@
26 28 vm.perPage = vm.perPage || 20;
27 29 vm.total = vm.total || 0;
28 30  
  31 + vm.calcArrayPages();
  32 + };
  33 +
  34 + AppPaginatorController.prototype.calcArrayPages = function() {
  35 + var vm = this;
  36 +
29 37 if ((vm.total % vm.perPage) === 0) {
30 38 vm.pages = vm.total / vm.perPage;
31 39 } else {
... ... @@ -35,6 +43,18 @@
35 43 vm.arraypages = new Array(Math.floor(vm.pages));
36 44 };
37 45  
  46 + AppPaginatorController.prototype.attachListeners = function() {
  47 + var vm = this;
  48 +
  49 + vm.$scope.$watch('vm.perPage', function(newValue/*, oldValue*/) {
  50 + vm.calcArrayPages();
  51 + });
  52 +
  53 + vm.$scope.$watch('vm.total', function(newValue/*, oldValue*/) {
  54 + vm.calcArrayPages();
  55 + });
  56 + };
  57 +
38 58 AppPaginatorController.prototype.showPage = function(pageIndex) {
39 59 var vm = this;
40 60  
... ...