1

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

3
  • can you add the output of console.log(stories) to your question ? Commented Nov 5, 2015 at 11:32
  • it will also be useful if you add console.log(data) inside RestangularProvider.addResponseInterceptor(function(data,... to see the structure of the received data. Commented Nov 5, 2015 at 11:37
  • I edited my original question and added a (huge) screenshot. Commented Nov 5, 2015 at 11:50

1 Answer 1

5

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();
})
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, this is what I was missing. Thanks!

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.