Restangular getList() does not return array of list items

Issue

I try to use Restangular to handle calls to my restful API.

Here is my code:

var baseStories = Restangular.all('stories/all');

baseStories.getList().then(function (stories) {
    console.log(stories);
})

The console.log shows the full restangularized array instead of an array of stories as I’d expect.

I use the RestangularProvider.addResponseInterceptor from the docs to unwrap the response data.

Has anyone an idea what I’m missing?

Edit:
Below is a screenshot of the console.log output from the code above. I see two stories (which is correct) and a bunch of Restangular methods. Is it possible to only get the stories?

Screenshot of console.log

Solution

Actually addResponseInterceptor must return restangularized element. It is written in the documentation:

https://github.com/mgonto/restangular#addresponseinterceptor

In order to get clean response you have to call plain() method on the response element:

var baseStories = Restangular.all('stories/all');

baseStories.getList().then(function (response) {
    $scope.stories = response.plain();
})

Answered By – rsobon

Answer Checked By – Candace Johnson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.