title: Implementing a dynamic pagination with UIBootstrap in AngularJS
body: <p>I'm doing a HTTP Request to the server and getting a result from the server or database with the expected data. Well, I don't know how to combine the result with my pagination. For now only the page numbers are correct. But click on a page number doesn't pass the next 10 items.</p>
  
  <p>At first my view:</p>
  
  <pre><code>...
  &lt;tr ng-repeat="person in filteredPersons"&gt;
        &lt;td&gt;{{ person.name }}&lt;/td&gt;
        &lt;td&gt;{{ person.age }}&lt;/td&gt;
        &lt;td&gt;{{ person.city }}&lt;/td&gt;
  &lt;/tr&gt;
  ...
  
  &lt;pagination boundary-links="true" 
                      total-items="totalItems" 
                      ng-model="currentPage" 
                      class="pagination-sm" 
                      previous-text="&amp;lsaquo;" 
                      next-text="&amp;rsaquo;" 
                      first-text="&amp;laquo;" 
                      last-text="&amp;raquo;"
                      items-per-page="itemsPerPage"&gt;
  &lt;/pagination&gt;
  ...
  </code></pre>
  
  <p>Then the Ctrl with the function:</p>
  
  <pre><code>$scope.currentPage = 1;
  $scope.itemsPerPage = 10;
  
  $scope.changeDate = function (datum) {
      CrudService.getByDay(datum).$promise.then(
           function (resp) {
              $scope.persons = resp;
              $scope.pageCount = function () {
                  return Math.ceil($scope.persons.length / $scope.itemsPerPage);
              };
  
              $scope.persons.$promise.then(
                   function () {
                      $scope.totalItems = $scope.persons.length;
                      $scope.$watch('currentPage + itemsPerPage', function () {
  
                            var begin = (($scope.currentPage - 1) * $scope.itemsPerPage),
                                end = begin + $scope.itemsPerPage;
  
                            $scope.filteredPersons = $scope.persons.slice(begin, end);
                      });
                   });
           });
  }
  </code></pre>
  
  <p>Which possibilities do I have? Maybe is it better to outsource the code in a filter?</p>