Sto tornando un array di oggetti dal server:
[{id: 1, name: "name"},{id: 2, name: "name2"}]
Ora uso angolare di risorse $query
per recuperare i dati mentre si aspetta un array. Quando i dati vengono ricevuti ottengo questo errore:
TypeError: value.push is not a function
C'è un problema con la risposta do da server =?
Fonte di errore:
// 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();
Servizio:
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'},
{
});
}
]);
farci [continua questa discussione in videochat] (http://chat.stackoverflow.com/rooms/ 83452/discussione-tra-Grundy-e-Kaspar). – Grundy