angularjs - $resource and get array -


i have api returns data following form (using tastypie):

{"meta":{      "limit": 20,       "next": null,       "offset": 0,       "previous": null,       "total_count": 4},       "objects": [           {            "id": 1,             "name": "name1",             "resource_uri": "/api/v1/operator/1",             "short_name": "na1"           },           {            "id": 2,             "name": "name2",             "resource_uri": "/api/v1/operator/2",             "short_name": "na2"           },            ...     ] } 

so thought have resource working, should have used:

var operator = $resource('http://127.0.0.1:8080\:8080/api/v1/operator/:operatorid',     {operatorid:'@id'},     {         query: {             method: 'get',             transformresponse: function (data) {                 console.log(json.parse(data).objects)                 return json.parse(data).objects;             },             isarray: true         }     }); 

but when set isarray true : got following error:

typeerror: object #<g> has no method 'push' 

if set isarray false, have no error object contains meta datas request...

not sure understand correctly $resource feature

since $resource automatically converts json string object, don't have call json.parse().

just do

var operator = $resource('http://127.0.0.1:8080\:8080/api/v1/operator/:operatorid', {     operatorid: '@id' }, {     query: {         method: 'get',         transformresponse: function (data) {             return data.meta.objects;         },         isarray: true     } }); 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -