Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 67e4997

Browse files
committedNov 30, 2016
fix(ui-sref-active-eq): Compare parameter values using typed parameters
1 parent c1989bc commit 67e4997

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
 

‎src/state.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
12621262

12631263
if (!isDefined(state)) { return undefined; }
12641264
if ($state.$current !== state) { return false; }
1265-
return params ? equalForKeys(state.params.$$values(params), $stateParams) : true;
1265+
1266+
return !params || objectKeys(params).reduce(function(acc, key) {
1267+
var paramDef = state.params[key];
1268+
return acc && !paramDef || paramDef.type.equals($stateParams[key], params[key]);
1269+
}, true);
12661270
};
12671271

12681272
/**
@@ -1338,7 +1342,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
13381342
}
13391343
}
13401344

1341-
return true;
1345+
return objectKeys(params).reduce(function(acc, key) {
1346+
var paramDef = state.params[key];
1347+
return acc && !paramDef || paramDef.type.equals($stateParams[key], params[key]);
1348+
}, true);
13421349
};
13431350

13441351

‎test/stateDirectivesSpec.js

+24
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,30 @@ describe('uiSrefActive', function() {
566566
expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('');
567567
}));
568568

569+
// Test for #3154
570+
it('should compare ui-sref-active-eq using typed parameters', inject(function($rootScope, $q, $compile, $state) {
571+
el = angular.element('<div><a ui-sref="arrayparam({ foo: [1,2,3] })" ui-sref-active-eq="active">foo 123</a></div>');
572+
template = $compile(el)($rootScope);
573+
$rootScope.$digest();
574+
575+
expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('');
576+
577+
$state.transitionTo('arrayparam', {foo: [1,2,3] });
578+
$q.flush();
579+
timeoutFlush();
580+
expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active');
581+
582+
$state.transitionTo('arrayparam', {foo: [1,2,3], bar: 'asdf' });
583+
$q.flush();
584+
timeoutFlush();
585+
expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active');
586+
587+
$state.transitionTo('arrayparam', {foo: [1,2] });
588+
$q.flush();
589+
timeoutFlush();
590+
expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('');
591+
}));
592+
569593
it('should update in response to ui-sref param expression changes', inject(function($rootScope, $q, $compile, $state) {
570594
el = angular.element('<div><a ui-sref="contacts.item.detail({ foo: fooId })" ui-sref-active="active">Contacts</a></div>');
571595
template = $compile(el)($rootScope);

0 commit comments

Comments
 (0)
Please sign in to comment.