Is it possible to specify the path of a custom $resource action ?
I would like to write something like:
angular.module('MyServices', [ 'ngResource' ]).factory('User', [ '$resource', ($resource)->
$resource('/users', {}, {
names: { path: '/names', method: 'GET', isArray: true }
})
])
So I can use it like:
User.names() # GET /users/names
It is not directly supported in the current version of AngularJS but there is a pull request open so there is chance that it will be supported in the near future.
Till then you've got 3 options:
1) Play with variables in the path:
$resource('/users/:names', {}, {
names: { params: {names: 'names'}, method: 'GET', isArray: true }
})
2) Use the $http service instead
3) Try the code from the mentioned PR on the monkey-patched version of AngularJS
Check the logs in this working Plunker (excerpt):
var app = angular.module('plunker', ['ngResource'])
.controller('MyController',
function($scope, $resource) {
var User = $resource(
'/users/:action',
{},
{
names:{
method:'GET',
params:{action:'names'}
}
}
);
$scope.users = User.get();
$scope.names = User.names();
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With