Skip to content

Commit

Permalink
fix(ui-sref): Allow sref state options to take a scope object
Browse files Browse the repository at this point in the history
  • Loading branch information
jhicken committed Sep 24, 2014
1 parent bde0dd0 commit b5f7b59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/stateDirectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function $StateRefDirective($state, $timeout) {
});

var update = function(newVal) {
if (newVal) params = newVal;
if (newVal) params = angular.copy(newVal);
if (!nav) return;

newHref = $state.href(ref.state, params, options);
Expand All @@ -120,7 +120,7 @@ function $StateRefDirective($state, $timeout) {
scope.$watch(ref.paramExpr, function(newVal, oldVal) {
if (newVal !== params) update(newVal);
}, true);
params = scope.$eval(ref.paramExpr);
params = angular.copy(scope.$eval(ref.paramExpr));
}
update();

Expand Down
14 changes: 14 additions & 0 deletions test/stateDirectivesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ describe('uiStateRef', function() {
$rootScope.$digest();
expect(el.attr('href')).toBe('#/contacts/3');
}));

it('should take an object as a parameter and update properly on digest churns', inject(function($rootScope, $q, $compile, $state) {

el = angular.element('<div><a ui-sref="contacts.item.detail(urlParams)">Contacts</a></div>');
template = $compile(el)($rootScope);

$rootScope.urlParams = { id:1 };
$rootScope.$digest();
expect(angular.element(template[0].querySelector('a')).attr('href')).toBe('#/contacts/1');

$rootScope.urlParams.id = 2;
$rootScope.$digest();
expect(angular.element(template[0].querySelector('a')).attr('href')).toBe('#/contacts/2');
}));
});

describe('links in html5 mode', function() {
Expand Down

0 comments on commit b5f7b59

Please sign in to comment.