Skip to content

Commit 5e8ead2

Browse files
committed
- fix related to the issue angular#875
1 parent a931154 commit 5e8ead2

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/ngResource/resource.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,9 @@ angular.module('ngResource', ['ng']).
310310

311311
actions = extend({}, DEFAULT_ACTIONS, actions);
312312

313-
function extractParams(data){
313+
function extractParams(data, actionParams){
314314
var ids = {};
315+
paramDefaults = extend(paramDefaults, actionParams);
315316
forEach(paramDefaults || {}, function(value, key){
316317
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
317318
});
@@ -366,7 +367,7 @@ angular.module('ngResource', ['ng']).
366367
var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
367368
$http({
368369
method: action.method,
369-
url: route.url(extend({}, extractParams(data), action.params || {}, params)),
370+
url: route.url(extend({}, extractParams(data, action.params || {}), params)),
370371
data: data
371372
}).then(function(response) {
372373
var data = response.data;

test/ngResource/resourceSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ describe("resource", function() {
118118
});
119119

120120

121+
it('should build resource with action default param reading the value from instance', function() {
122+
$httpBackend.expect('POST', '/Customer/123').respond();
123+
var R = $resource('/Customer/:id', {}, {post: {method: 'POST', params: {id: '@id'}}});
124+
125+
var inst = new R({id:123});
126+
expect(inst.id).toBe(123);
127+
128+
inst.$post();
129+
});
130+
131+
121132
it('should handle multiple params with same name', function() {
122133
var R = $resource('/:id/:id');
123134

0 commit comments

Comments
 (0)