javascript - Add custom callback for a resource -


i'm using angularjs 1.1.5 , have service provider resource, there 1 use case returned response needs reparsed , info need normalized, special case resource used across project , it's not desired have use different resource or custom filter everywhere it's called.

is there way add function when returning query or method, without affecting normal behavior.

it should like, whenever there call resource method, execute callback transformations on data , return data expected.

here way service implemented.

  factory('seccion', ['$resource', 'api_url', function($resource, api_url) {     var seccion = $resource(api_url + 'secciones/:seccionid/:nestedresource/:nestedid',       {         seccionid: '@seccionid',         nestedresource: '@nestedresource',         nestedid: '@nestedid'       },       {       getwithnotas: {         method: 'get',         params: {           nestedresource: 'notas',           order: 'fecha,desc;hora,desc',           q: 'activo,=,1;borrado,=,0',           count: 9,           offset: 0         }       }     });     return seccion;   }]) 

you can invoke method callbacks. here quoting angular $resource documentation.

the action methods on class object or instance object can invoked following parameters:

  • http "class" actions: resource.action([parameters], [success], [error])
  • non-get "class" actions: resource.action([parameters], postdata, [success], [error])
  • non-get instance actions: instance.$action([parameters], [success], [error])

so can invoke method callback :-

var s = seccion.getwithnotas({params}, function() {     dosomethingto(s);  } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -