Suppose I have
angular.factory('Service', [
'$resource', function ($resource) {
return $resource('/path/:id', {id: '@id'});
}])
If in my controller I do
var s = new Service({id: 123});
s.$query();
it sends a request to /path
, but I expected it to send a request to /path/123
. Why does it do that and how to set the parameter?
I do not want to provide any parameters to $query()
. I want to set the "default" ones. The one denoted by @id
.
$query
is used to get a list of records. What you want is $get
var s = Service.get({id :123}, function optionalFn(){});
See more here
I think the example controller here is actually sending the id parameter to the factory itself, which the factory doesn't need. With the way this is set up, you would need to send a parameter inside query() or you would have the option of changing the resource path id value inside the factory code from '@id' to 123. I believe '@id' is telling it to look for the id parameter in a call like query({id:123}).