From b5f7b59692ce4933e2d63eb5df3f50a4ba68ccc0 Mon Sep 17 00:00:00 2001 From: Jeff Hicken Date: Wed, 24 Sep 2014 11:12:17 -0600 Subject: [PATCH] fix(ui-sref): Allow sref state options to take a scope object --- src/stateDirectives.js | 4 ++-- test/stateDirectivesSpec.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/stateDirectives.js b/src/stateDirectives.js index ba730ce29..b404578da 100644 --- a/src/stateDirectives.js +++ b/src/stateDirectives.js @@ -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); @@ -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(); diff --git a/test/stateDirectivesSpec.js b/test/stateDirectivesSpec.js index 1e9e1bead..da000b603 100644 --- a/test/stateDirectivesSpec.js +++ b/test/stateDirectivesSpec.js @@ -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('
Contacts
'); + 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() {