aboutsummaryrefslogtreecommitdiffstats
path: root/src/ngResource
diff options
context:
space:
mode:
authorPascal Corpet2012-07-04 10:07:09 +0200
committerIgor Minar2012-11-28 16:01:57 +0100
commitcc42c99bec6a03d6c41b8e1d29ba2b1f5c16b87d (patch)
treeef3ebb8c2c792da08ab642492d1f347f6459aba1 /src/ngResource
parent3c7bfa77aad5e3f8c71bc63a7cd91c2586d8560a (diff)
downloadangular.js-cc42c99bec6a03d6c41b8e1d29ba2b1f5c16b87d.tar.bz2
feat($resource): allow dynamic default parameters
Default resource params can now be calculated at runtime if defined via a function.
Diffstat (limited to 'src/ngResource')
-rw-r--r--src/ngResource/resource.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js
index db86eb41..28de3f7d 100644
--- a/src/ngResource/resource.js
+++ b/src/ngResource/resource.js
@@ -22,7 +22,8 @@
* `/user/:username`.
*
* @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in
- * `actions` methods.
+ * `actions` methods. If any of the parameter value is a function, it will be executed every time
+ * when a param value needs to be obtained for a request (unless the param was overriden).
*
* Each key value in the parameter object is first bound to url template if present and then any
* excess keys are appended to the url search query after the `?`.
@@ -46,10 +47,12 @@
* resource object.
* - `method` – {string} – HTTP request method. Valid methods are: `GET`, `POST`, `PUT`, `DELETE`,
* and `JSONP`
- * - `params` – {object=} – Optional set of pre-bound parameters for this action.
+ * - `params` – {Object=} – Optional set of pre-bound parameters for this action. If any of the
+ * parameter value is a function, it will be executed every time when a param value needs to be
+ * obtained for a request (unless the param was overriden).
* - isArray – {boolean=} – If true then the returned object for this action is an array, see
* `returns` section.
- * - `headers` – {object=} – Optional HTTP headers to send
+ * - `headers` – {Object=} – Optional HTTP headers to send
*
* @returns {Object} A resource "class" object with methods for the default set of resource actions
* optionally extended with custom `actions`. The default set contains these actions:
@@ -316,6 +319,7 @@ angular.module('ngResource', ['ng']).
var ids = {};
actionParams = extend({}, paramDefaults, actionParams);
forEach(actionParams, function(value, key){
+ if (isFunction(value)) { value = value(); }
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
});
return ids;