diff --git a/src/ng1/stateDirectives.ts b/src/ng1/stateDirectives.ts index 298b3cfb1..bad64c421 100644 --- a/src/ng1/stateDirectives.ts +++ b/src/ng1/stateDirectives.ts @@ -129,6 +129,7 @@ function $StateRefDirective($state, $timeout) { var def = { state: ref.state, href: null, params: null, options: null }; var type = getTypeInfo(element); var active = uiSrefActive[1] || uiSrefActive[0]; + var unlinkInfoFn = null; def.options = extend(defaultOpts(element, $state), attrs.uiSrefOpts ? scope.$eval(attrs.uiSrefOpts) : {}); @@ -136,7 +137,8 @@ function $StateRefDirective($state, $timeout) { if (val) def.params = angular.copy(val); def.href = $state.href(ref.state, def.params, def.options); - if (active) active.$$addStateInfo(ref.state, def.params); + if (unlinkInfoFn) unlinkInfoFn(); + if (active) unlinkInfoFn = active.$$addStateInfo(ref.state, def.params); if (def.href !== null) attrs.$set(type.attr, def.href); }; @@ -185,10 +187,7 @@ function $StateRefDynamicDirective($state, $timeout) { def.state = group[0]; def.params = group[1]; def.options = group[2]; def.href = $state.href(def.state, def.params, def.options); - if (unlinkInfoFn) { - unlinkInfoFn(); - unlinkInfoFn = null; - } + if (unlinkInfoFn) unlinkInfoFn(); if (active) unlinkInfoFn = active.$$addStateInfo(def.state, def.params); if (def.href) attrs.$set(type.attr, def.href); } diff --git a/test/stateDirectivesSpec.js b/test/stateDirectivesSpec.js index df1d3fa7b..c3b20948d 100644 --- a/test/stateDirectivesSpec.js +++ b/test/stateDirectivesSpec.js @@ -615,6 +615,24 @@ describe('uiSrefActive', function() { expect(angular.element(template[0].querySelector('a')).attr('class')).toBe(''); })); + it('should update in response to ui-sref param expression changes', inject(function($rootScope, $q, $compile, $state) { + el = angular.element('
Contacts
'); + template = $compile(el)($rootScope); + $rootScope.fooId = 'bar' + $rootScope.$digest(); + + expect(angular.element(template[0].querySelector('a')).attr('class')).toBe(''); + $state.transitionTo('contacts.item.detail', { id: 5, foo: 'bar' }); + $q.flush(); + timeoutFlush(); + expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active'); + + $rootScope.fooId = 'baz' + $q.flush(); + timeoutFlush(); + expect(angular.element(template[0].querySelector('a')).attr('class')).toBe(''); + })); + it('should match on child states', inject(function($rootScope, $q, $compile, $state) { template = $compile('
Contacts
')($rootScope); $rootScope.$digest();