Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 9713102

Browse files
committed
Allow dynamic default parameters of
1 parent a8b0400 commit 9713102

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/ngResource/resource.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ angular.module('ngResource', ['ng']).
308308
function extractParams(data){
309309
var ids = {};
310310
forEach(paramDefaults || {}, function(value, key){
311+
if (isFunction(value)) { value = value(); }
311312
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
312313
});
313314
return ids;

test/ngResource/resourceSpec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,17 @@ describe("resource", function() {
298298
});
299299

300300

301+
it('should bind default dynamic parameters', function() {
302+
$httpBackend.expect('GET', '/CreditCard/123.visa?minimum=0.05').respond({id: 123});
303+
var minimum = 5;
304+
var Visa = CreditCard.bind({verb:'.visa', minimum: function() { return minimum; }});
305+
minimum = 0.05;
306+
var visa = Visa.get({id:123});
307+
$httpBackend.flush();
308+
expect(visa).toEqualData({id:123});
309+
});
310+
311+
301312
it('should exercise full stack', function() {
302313
var Person = $resource('/Person/:id');
303314

0 commit comments

Comments
 (0)