title: call data dynamically from API using pagination
body: <p>I need help with pagination in AngularJS application.</p>
  
  <p>My URL: <code>localhost/myurl</code> gives me data as:</p>
  
  <pre><code>Success: {
      total: 349,
      per_page: 10,
      current_page: 1,
      last_page: 35,
      from: 1,
      to: 10,
      data: [{
          name: 'name1',
          age: 'age1'
      }, {
          name: 'name2',
          age: 'age2'
      }]
  }
  </code></pre>
  
  <p>My view:</p>
  
  <pre><code>&lt;div ng-controller="DemoCtrl"&gt;
      &lt;p&gt;&lt;strong&gt;Page:&lt;/strong&gt; {{tableParams.page()}}&lt;/p&gt;
      &lt;p&gt;&lt;strong&gt;Count per page:&lt;/strong&gt; {{tableParams.count()}}&lt;/p&gt;
      &lt;table ng-table="tableParams" class="table"&gt;
          &lt;tr ng-repeat="user in $data"&gt;
              &lt;td data-title="'Name'"&gt;{{user.Name}}&lt;/td&gt;
              &lt;td data-title="'Email'"&gt;{{user.EMAIL}}&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>my js</p>
  
  <pre><code>var app = angular.module('main', ['ngTable'])
  .service('myservice', ['$http', function($http){
      this.getData = function(url){
          return $http.get(url);
      };
  }])
  .controller('DemoCtrl',['$scope', 'ngTableParams', 'myservice', function($scope, ngTableParams, myservice) {
      myservice.getData('http://localhost/testpagination/public/testpagination').success(function(response){
          if (response.Success) {
              console.log(response.Success.data);
              var data = response.Success.data;
              $scope.tableParams = new ngTableParams({
                  page: 1,            // show first page
                  count: 10           // count per page
              }, {
                  total: response.Success.total, // length of data
                  getData: function($defer, params) {
                      $defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                  }
              });
          } else if (response.Fail) {
              console.log('i got fail.');
          }
      }).error(function(response){
          console.log('http error');
      });
  }]); 
  </code></pre>
  
  <p>I am getting my first ten (1 to 10) data for the first time but how may I proceed to the next page (call second pagination API) dynamically?</p>