I am returning an array of objects from the server:
[{id: 1, name: "name"},{id: 2, name: "name2"}]
Now I use angular -resource $query to retrieve the data since it expects an array. When the data is received, I get this error:
TypeError: value.push is not a function
Is there a problem with the answer I give from server =?
Source of error:
// jshint +W018 if (action.isArray) { value.length = 0; forEach(data, function(item) { if (typeof item === "object") { value.push(new Resource(item)); } else { // Valid JSON values may be string literals, and these should not be converted // into objects. These items will not have access to the Resource prototype // methods, but unfortunately there value.push(item); } }); } else { shallowClearAndCopy(data, value); value.$promise = promise; } }
Controller:
var stream = []; stream = new VideoStream({param: 'streamTypes'}); stream.$query();
Services:
app.service('DataService', [ '$resource', 'Common', '$rootScope', function($resource, Common, $rootScope) { return $resource($rootScope.appWebRoot + "myUrl/:param", {param: '@param'}, { }); } ]);



VideoStream:
app.service('VideoStream', [ '$resource', 'Common', '$rootScope', function($resource, Common, $rootScope) { return $resource($rootScope.appWebRoot + "videoStreams/api/:param", {param: '@param'}, { }); } ]);
javascript angularjs angular-resource
Kaspar
source share