8

In DRF I have added pagination limit to 100 'PAGINATE_BY': 100, since Restangular expects results in array form, I had to use the below meta extractor function in my angular app module

var app = angular.module("myapp", ["restangular"].config(function(
            RestangularProvider){

  RestangularProvider.setResponseExtractor(function(response, operation, what, url) {
    if (operation === "getList") {
        var newResponse = response.results;
        newResponse._resultmeta = {
            "count": response.count,
            "next": response.next,
            "previous": response.previous
        };
        return newResponse;
    }

    return response;
    });
});

and my controller looks like

app.controller('DataCtrl',function($scope, Restangular){

    var resource = Restangular.all('myapp/api/dataendpoint/');
        resource.getList().then(function(data){
        $scope.records = data;
    });    
}

Meta info is not available in controller, how do I paginate if there are more than 100 records available?

1 Answer 1

2
+50

I suppose you could simply call:

RestangularProvider.addResponseExtractor(function(data, operation, what, url, response) {
  if (operation === "getList") {
      data._resultmeta = {
          "count": response.count,
          "next": response.next,
          "previous": response.previous
      };
      return data;
  }

  return response;
});

and

var page = 2;
var resource = Restangular.all('myapp/api/dataendpoint/');
resource.getList({page: page}).then(function(data){
  console.log(data._resultmeta.next ? 'there is more pages' : 'You reach the end');
});

I'm not usual with Rectangular but Django Rest Framework support pagination from query parameter

Sign up to request clarification or add additional context in comments.

1 Comment

for latest version of restangular use addResponseInterceptor() instead of addResponseExtractor()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.