The documentation here says that:
url – {string} – action specific url override.
The url templating is supported just like for the resource-level urls.
I would like to use this good feature, I tried this:
angular.module("experience", ['ngResource'])
.factory('Experience', function ($resource, identity) {
return $resource("api/experiences/:id", {}, {
queryAll : {
method : 'GET',
url : 'api/companies/' + identity.id + '/experiences',
isArray : true
}
});
});
You see I am trying to overwrite the url for queryAll method. but this does not work, the query still sends the url api/experiences. is this really supported or I am doing somehting wrong? thanks for any help.
I have a very similar problem in my project. The url couldn't be overridden in resource actions. I am using Angular 1.2.0 and it should support the feature since 1.1.4. So I checked the Angular API reference, CHANGELOG, but no luck. Then I dug into the source code and noticed that the logic of overriding url isn't there. That's the root cause of the problem. I updated Angular to 1.2.0, but I forgot to update angular-resource.js
to the corresponding version.
So, long story short: check the version of angular-resource.js
I am not sure if you cann access properties of identity
in the url override, but you can try something like this:
return $resource("api/experiences/:id", {}, {
queryAll : {
method : 'GET',
url : 'api/companies/:id/experiences',
params : { id: identity.id },
isArray : true
}
});
The id: identity.id
tells angular to use the id property of identity
, (if it exists).
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