From 243716eabf43e0b41aa8b6d26000592278d4eb34 Mon Sep 17 00:00:00 2001 From: cyrilf Date: Thu, 20 Aug 2015 17:51:54 +0200 Subject: [PATCH] feat($IncludedByStateFilter): add parameters to $IncludedByStateFilter PR linked to #1736 but for version feature-1.0 Add parameters to the $IncludedByStateFilter: - params - options This allows to use more parameters on this filter and not only the fullOrPartialStatename parameter. Thanks to this improvement, the following now works (takes in account the id param):
It works
Related doc: http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state#methods_includes --- src/state/stateFilters.ts | 4 ++-- test/stateFiltersSpec.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/state/stateFilters.ts b/src/state/stateFilters.ts index 0ded94544..3d26612a4 100644 --- a/src/state/stateFilters.ts +++ b/src/state/stateFilters.ts @@ -27,8 +27,8 @@ export function $IsStateFilter($state) { */ $IncludedByStateFilter.$inject = ['$state']; export function $IncludedByStateFilter($state) { - return function(state) { - return $state.includes(state); + return function(state, params, options) { + return $state.includes(state, params, options); }; } diff --git a/test/stateFiltersSpec.js b/test/stateFiltersSpec.js index a0733a587..64722e209 100644 --- a/test/stateFiltersSpec.js +++ b/test/stateFiltersSpec.js @@ -28,7 +28,8 @@ describe('includedByState filter', function() { $stateProvider .state('a', { url: '/' }) .state('a.b', { url: '/b' }) - .state('c', { url: '/c' }); + .state('c', { url: '/c' }) + .state('d', { url: '/d/:id' }); })); it('should return true if the current state exactly matches the input state', inject(function($parse, $state, $q, $rootScope) { @@ -48,4 +49,16 @@ describe('includedByState filter', function() { $q.flush(); expect($parse('"a" | includedByState')($rootScope)).toBe(false); })); + + it('should return true if the current state include input state and params', inject(function($parse, $state, $q, $rootScope) { + $state.go('d', { id: 123 }); + $q.flush(); + expect($parse('"d" | includedByState:{ id: 123 }')($rootScope)).toBe(true); + })); + + it('should return false if the current state does not include input state and params', inject(function($parse, $state, $q, $rootScope) { + $state.go('d', { id: 2377 }); + $q.flush(); + expect($parse('"d" | includedByState:{ id: 123 }')($rootScope)).toBe(false); + })); });