aboutsummaryrefslogtreecommitdiffstats
path: root/src/ngResource/resource.js
diff options
context:
space:
mode:
authorpetrovalex2012-05-11 23:14:59 +0300
committerMisko Hevery2012-09-06 16:06:22 -0700
commit10e1c759f4602d993a76b0eacf6a2d04c8880017 (patch)
tree1f5dc6c6c68f346e8b1a073900c86eef54dc7412 /src/ngResource/resource.js
parent6c67719dfa6ff3f2a15a8e1e7660cf2e6e9155b0 (diff)
downloadangular.js-10e1c759f4602d993a76b0eacf6a2d04c8880017.tar.bz2
fix($resource): ignore undefined parameters
- $resource should handle multiple params with same name - ignore slashes of undefined parameters - fix default parameters issue, mentioned in #875 Closes #875 Closes #782
Diffstat (limited to 'src/ngResource/resource.js')
-rw-r--r--src/ngResource/resource.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js
index 166fc9b8..cd03d2d2 100644
--- a/src/ngResource/resource.js
+++ b/src/ngResource/resource.js
@@ -280,12 +280,17 @@ angular.module('ngResource', ['ng']).
url: function(params) {
var self = this,
url = this.template,
+ val,
encodedVal;
params = params || {};
forEach(this.urlParams, function(_, urlParam){
- encodedVal = encodeUriSegment(params[urlParam] || self.defaults[urlParam] || "");
- url = url.replace(new RegExp(":" + urlParam + "(\\W)"), encodedVal + "$1");
+ if (val = (params[urlParam] || self.defaults[urlParam])) {
+ encodedVal = encodeUriSegment(val);
+ url = url.replace(new RegExp(":" + urlParam + "(\\W)", "g"), encodedVal + "$1");
+ } else {
+ url = url.replace(new RegExp("/?:" + urlParam + "(\\W)", "g"), '$1');
+ }
});
url = url.replace(/\/?#$/, '');
var query = [];
@@ -306,8 +311,9 @@ angular.module('ngResource', ['ng']).
actions = extend({}, DEFAULT_ACTIONS, actions);
- function extractParams(data){
+ function extractParams(data, actionParams){
var ids = {};
+ paramDefaults = extend(paramDefaults, actionParams);
forEach(paramDefaults || {}, function(value, key){
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
});
@@ -362,7 +368,7 @@ angular.module('ngResource', ['ng']).
var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
$http({
method: action.method,
- url: route.url(extend({}, extractParams(data), action.params || {}, params)),
+ url: route.url(extend({}, extractParams(data, action.params || {}), params)),
data: data,
headers: extend({}, action.headers || {})
}).then(function(response) {