samedi 18 avril 2015

Forgive parameters in angular service call if ones set in service itself

Given angular service:



angular.module('likes').factory('Like', ['$resource', function($resource) {
return $resource('/like/:type/:id', {
id: '@id',
type: '@type'
}, {
new: {
method: 'POST'
},
destroy: {
method: 'DELETE',
params: {
type: ''
}
}
});
}]);


new() method's REST endpoint requires type to be sent (i.e. POST /like/article/42)


destroy() method's REST endpoint doesn't require type (i.e. DELETE /like/42)


So, I just override type in destroy params. Anyway this



Like.destroy({
id: 42,
type: 'article'
})


will send request to '/like/article/42'


Of course I can just avoid passing type in this case, but depends on some reason I need invocation of destroy() to look like that. Is there a way to override default params for some methods of angular service?


Aucun commentaire:

Enregistrer un commentaire