Restangular GET request returns 100 records only

Issue

I am using a Restangular library in my angularjs application.I want to retrieve all registered user’s information from rest api.Whenever I make Restangular GET request to do so it retrieves only 100 records while I have around 250+ users for my website.I’ve tried using

Restangular.all('url').getList({limit:200,offset:0})
  .then(function (success) {
     //some code    
   });

This was the wayout mentioned here but it isn’t working for me.

Solution

Found solution after some time

RestFullResponse.all('url').getList().then(function (success) {
   var headers = success.headers();
   var currentpage = headers['x-pager-current-page'];
   var lastpage = headers['x-pager-last-page'];
   for(currentpage; currentpage<=lastpage; currentpage++) {
     var param = {
       "page_entries": 100,
       "page":currentpage,
       "offset": (currentpage-1)*this.page_entries
     };             
     RestFullResponse.all('url').getList(param).then(function (success) {
        personList = personList.concat(success['data']);
     });
   }
});

Answered By – Shreyas Nargund

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.