Paginating JSON results in AngularJS
<p>I've built an app that uses the moviedb database to query for a list of current movies. I get a JSON object in response, but need to be able to paginate the results and make a request for subsequent pages (e.g., <code>http://api.themoviedb.org/3/movie/now_playing&amp;page=2</code>) where <code>&amp;page={{nextPage}}</code> as a query parameter.</p>

<p>I currently have this as my controller:</p>

<pre><code>app.controller('CustomerController', function($scope, $http, $timeout, $modal, $log) {

$http.get("http://api.themoviedb.org/3/movie/now_playing")
    .success(function(response) {
      console.log(response);
      $scope.page = response.page;
      $scope.results = response.results;
      $scope.currentPage = response.page;
      $scope.pageSize = response.total_pages;
    });
</code></pre>

<p>and using this to display results and the pagination UI:</p>

<pre><code>&lt;div ng-app="app"&gt;

  &lt;div ng-controller="CustomerController"&gt;
    &lt;div class="container"&gt;
      &lt;div class="row"&gt;
        &lt;div ng-repeat="items in results"&gt;
          &lt;a ng-click="open(items)" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 thumbnail"&gt;
            &lt;img ng-if="items.poster_path" ng-src="http://image.tmdb.org/t/p/w342/{{items.poster_path}}"&gt;
            &lt;div class="caption" ng-hide="items.poster_path"&gt;
              &lt;h3&gt;{{items.title}}&lt;/h3&gt;
            &lt;/div&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="row"&gt;
      &lt;div class="container"&gt; Page {{currentPage}} of {{pageSize}}
        &lt;button class="btn btn-default" ng-disabled="currentPage == 0" ng-click="currentPage=currentPage-1"&gt;Previous&lt;/button&gt;
        &lt;button class="btn btn-default" ng-disabled="currentPage &gt;= pageSize - 1" ng-click="currentPage=currentPage+1"&gt;Next&lt;/button&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
</code></pre>

<p>How can I create the function to make subsequent API calls to pull in the next or previous page results? I assume it should be setting a dynamic parameter from the pagination button and appending it to the end of the API call URL, but not sure how to implement this.</p>