|
53 | 53 | * - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of the |
54 | 54 | * parameter value is a function, it will be executed every time when a param value needs to be |
55 | 55 | * obtained for a request (unless the param was overriden). |
| 56 | + * - **`url`** – {string} – action specific `url` override. The url templating is supported just like |
| 57 | + * for the resource-level urls. |
56 | 58 | * - **`isArray`** – {boolean=} – If true then the returned object for this action is an array, see |
57 | 59 | * `returns` section. |
58 | 60 | * - **`transformRequest`** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` – |
@@ -306,30 +308,32 @@ angular.module('ngResource', ['ng']). |
306 | 308 | function Route(template, defaults) { |
307 | 309 | this.template = template = template + '#'; |
308 | 310 | this.defaults = defaults || {}; |
309 | | - var urlParams = this.urlParams = {}; |
310 | | - forEach(template.split(/\W/), function(param){ |
311 | | - if (param && (new RegExp("(^|[^\\\\]):" + param + "\\W").test(template))) { |
312 | | - urlParams[param] = true; |
313 | | - } |
314 | | - }); |
315 | | - this.template = template.replace(/\\:/g, ':'); |
| 311 | + this.urlParams = {}; |
316 | 312 | } |
317 | 313 |
|
318 | 314 | Route.prototype = { |
319 | | - setUrlParams: function(config, params) { |
| 315 | + setUrlParams: function(config, params, actionUrl) { |
320 | 316 | var self = this, |
321 | | - url = this.template, |
| 317 | + url = actionUrl || self.template, |
322 | 318 | val, |
323 | 319 | encodedVal; |
324 | 320 |
|
| 321 | + var urlParams = self.urlParams = {}; |
| 322 | + forEach(url.split(/\W/), function(param){ |
| 323 | + if (param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) { |
| 324 | + urlParams[param] = true; |
| 325 | + } |
| 326 | + }); |
| 327 | + url = url.replace(/\\:/g, ':'); |
| 328 | + |
325 | 329 | params = params || {}; |
326 | | - forEach(this.urlParams, function(_, urlParam){ |
| 330 | + forEach(self.urlParams, function(_, urlParam){ |
327 | 331 | val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam]; |
328 | 332 | if (angular.isDefined(val) && val !== null) { |
329 | 333 | encodedVal = encodeUriSegment(val); |
330 | | - url = url.replace(new RegExp(":" + urlParam + "(\\W)", "g"), encodedVal + "$1"); |
| 334 | + url = url.replace(new RegExp(":" + urlParam + "(\\W|$)", "g"), encodedVal + "$1"); |
331 | 335 | } else { |
332 | | - url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W)", "g"), function(match, |
| 336 | + url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W|$)", "g"), function(match, |
333 | 337 | leadingSlashes, tail) { |
334 | 338 | if (tail.charAt(0) == '/') { |
335 | 339 | return tail; |
@@ -427,7 +431,7 @@ angular.module('ngResource', ['ng']). |
427 | 431 | } |
428 | 432 | }); |
429 | 433 | httpConfig.data = data; |
430 | | - route.setUrlParams(httpConfig, extend({}, extractParams(data, action.params || {}), params)); |
| 434 | + route.setUrlParams(httpConfig, extend({}, extractParams(data, action.params || {}), params), action.url); |
431 | 435 |
|
432 | 436 | function markResolved() { value.$resolved = true; } |
433 | 437 |
|
|
0 commit comments