i returning array of objects server:
[{id: 1, name: "name"},{id: 2, name: "name2"}] now use angular-resource $query fetch data expects array. when data received error:
typeerror: value.push not function is there issue response give 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 string literals, , these should not converted // objects. these items not have access resource prototype // methods, unfortunately there value.push(item); } }); } else { shallowclearandcopy(data, value); value.$promise = promise; } } controller:
var stream = []; stream = new videostream({param: 'streamtypes'}); stream.$query(); service:
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'}, { }); } ]);
the problem have creating instance of resource object
var stream = []; stream = new videostream({param: 'streamtypes'}); //this problem. $resource expecting array. stream.$query(); //this instance method. //all need is: var stream = []; stream = videostream({param: 'streamtypes'}).query(); from https://docs.angularjs.org/api/ngresource/service/$resource:
$resource returns:
a resource "class" object methods default set of resource actions optionally extended custom actions. default set contains these actions:
{ 'get': {method:'get'}, 'save': {method:'post'}, 'query': {method:'get', isarray:true}, 'remove': {method:'delete'}, 'delete': {method:'delete'} };calling these methods invoke $http specified http method, destination , parameters. when data returned server object instance of resource class. actions save, remove , delete available on methods $ prefix
Comments
Post a Comment