title: Angular $resource recursive query
body: <p>From the API I'm working on I need to take 2 different lists and I need to take in chunks of 20 items to avoid server timeouts.</p>
  
  <p>What I built actually is this:</p>
  
  <pre><code>Items1.query().$promise
  .then(function (data) {
    $scope.items1 = data.list;
    return Items2.query().$promise;
  })
  .then(function (data) {
    $scope.items2 = data.list;
  });
  </code></pre>
  
  <p>With this code I'm downloading the entire list of objects.</p>
  
  <p>Both the query return:</p>
  
  <pre><code>{
      list: [...],
      next: true,
      limit: 20,
      last: 20
  }
  </code></pre>
  
  <p>Basically it is a pagination system.</p>
  
  <p>Both services are like this:</p>
  
  <pre><code>App.factory('Items1', ['$resource',
      function($resource) {
          return $resource('items1/:item1Id', { storeId: '@id'
          }, {
              query: {
                  method: 'GET',
                  isArray: false
              },
              update: {
                  method: 'PUT'
              }
          });
      }
  ]);
  </code></pre>
  
  <p>I don't really know how to make recursive function with $resource in order to push those items in chunks of 20.</p>