Skip to content

Commit b5f7b59

Browse files
committed
fix(ui-sref): Allow sref state options to take a scope object
1 parent bde0dd0 commit b5f7b59

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/stateDirectives.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function $StateRefDirective($state, $timeout) {
100100
});
101101

102102
var update = function(newVal) {
103-
if (newVal) params = newVal;
103+
if (newVal) params = angular.copy(newVal);
104104
if (!nav) return;
105105

106106
newHref = $state.href(ref.state, params, options);
@@ -120,7 +120,7 @@ function $StateRefDirective($state, $timeout) {
120120
scope.$watch(ref.paramExpr, function(newVal, oldVal) {
121121
if (newVal !== params) update(newVal);
122122
}, true);
123-
params = scope.$eval(ref.paramExpr);
123+
params = angular.copy(scope.$eval(ref.paramExpr));
124124
}
125125
update();
126126

test/stateDirectivesSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,20 @@ describe('uiStateRef', function() {
243243
$rootScope.$digest();
244244
expect(el.attr('href')).toBe('#/contacts/3');
245245
}));
246+
247+
it('should take an object as a parameter and update properly on digest churns', inject(function($rootScope, $q, $compile, $state) {
248+
249+
el = angular.element('<div><a ui-sref="contacts.item.detail(urlParams)">Contacts</a></div>');
250+
template = $compile(el)($rootScope);
251+
252+
$rootScope.urlParams = { id:1 };
253+
$rootScope.$digest();
254+
expect(angular.element(template[0].querySelector('a')).attr('href')).toBe('#/contacts/1');
255+
256+
$rootScope.urlParams.id = 2;
257+
$rootScope.$digest();
258+
expect(angular.element(template[0].querySelector('a')).attr('href')).toBe('#/contacts/2');
259+
}));
246260
});
247261

248262
describe('links in html5 mode', function() {

0 commit comments

Comments
 (0)