AngularJS and complex JSON returned by django tastypie AngularJS and complex JSON returned by django tastypie angularjs angularjs

AngularJS and complex JSON returned by django tastypie


If you wanted to avoid using an additional library, you should be able to do the following:

$resource('/api/v1/reminder/', {}, {    query: {        method: 'GET',        isArray: true,        transformResponse: $http.defaults.transformResponse.concat([            function (data, headersGetter) {                return data.objects;            }        ])    }});

This will append your transform to $HttpProvider's default transformer.

Note: Correct me if I'm wrong on this one but I believe this feature requires v1.1.2 or greater.


You may want to try something like restangular.

There is some configuration needed to make that work. An example is here.


I ended up doing the following in order to preserve the meta object directly on the results returned by Reminder.query() (expanding on the answer from @moderndegree).

var Reminder = $resource('/api/v1/reminder/', {}, {  query: {    method: 'GET',    isArray: true,    transformResponse: $http.defaults.transformResponse.concat([      function (data, headersGetter) {          return data.objects;      }    ]),    interceptor: {      response: function(response) {        response.resource.meta = response.data.meta;      }    }  }});

That allows you to get the meta value directly on the returned object:

var reminders = Reminder.query(...);console.log(reminders.meta); // Returns `meta` as expected.

I think it would also be possible to do something similar inside the callback from Reminder.query since the response object is available there as well.