From 67e4997eadfc1f7f5af8efd7cb676218cc69129e Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Tue, 29 Nov 2016 18:47:42 -0600 Subject: [PATCH] fix(ui-sref-active-eq): Compare parameter values using typed parameters --- src/state.js | 11 +++++++++-- test/stateDirectivesSpec.js | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/state.js b/src/state.js index 652d282c4..1f31f8412 100644 --- a/src/state.js +++ b/src/state.js @@ -1262,7 +1262,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) { if (!isDefined(state)) { return undefined; } if ($state.$current !== state) { return false; } - return params ? equalForKeys(state.params.$$values(params), $stateParams) : true; + + return !params || objectKeys(params).reduce(function(acc, key) { + var paramDef = state.params[key]; + return acc && !paramDef || paramDef.type.equals($stateParams[key], params[key]); + }, true); }; /** @@ -1338,7 +1342,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) { } } - return true; + return objectKeys(params).reduce(function(acc, key) { + var paramDef = state.params[key]; + return acc && !paramDef || paramDef.type.equals($stateParams[key], params[key]); + }, true); }; diff --git a/test/stateDirectivesSpec.js b/test/stateDirectivesSpec.js index 7966f57c5..2daaf8c05 100644 --- a/test/stateDirectivesSpec.js +++ b/test/stateDirectivesSpec.js @@ -566,6 +566,30 @@ describe('uiSrefActive', function() { expect(angular.element(template[0].querySelector('a')).attr('class')).toBe(''); })); + // Test for #3154 + it('should compare ui-sref-active-eq using typed parameters', inject(function($rootScope, $q, $compile, $state) { + el = angular.element('
foo 123
'); + template = $compile(el)($rootScope); + $rootScope.$digest(); + + expect(angular.element(template[0].querySelector('a')).attr('class')).toBe(''); + + $state.transitionTo('arrayparam', {foo: [1,2,3] }); + $q.flush(); + timeoutFlush(); + expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active'); + + $state.transitionTo('arrayparam', {foo: [1,2,3], bar: 'asdf' }); + $q.flush(); + timeoutFlush(); + expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active'); + + $state.transitionTo('arrayparam', {foo: [1,2] }); + $q.flush(); + timeoutFlush(); + 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);