From 963f6e71633b9c3a266f3991d79089b7d14786b4 Mon Sep 17 00:00:00 2001 From: cyrilf Date: Thu, 5 Feb 2015 16:47:45 +0100 Subject: [PATCH] feat($IncludedByStateFilter): add parameters to $IncludedByStateFilter 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
Closes #1735 --- src/stateFilters.js | 4 ++-- test/stateFiltersSpec.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/stateFilters.js b/src/stateFilters.js index e0a117580..74501e3ba 100644 --- a/src/stateFilters.js +++ b/src/stateFilters.js @@ -27,8 +27,8 @@ function $IsStateFilter($state) { */ $IncludedByStateFilter.$inject = ['$state']; function $IncludedByStateFilter($state) { - var includesFilter = function (state) { - return $state.includes(state); + var includesFilter = function (state, params, options) { + return $state.includes(state, params, options); }; includesFilter.$stateful = true; return includesFilter; diff --git a/test/stateFiltersSpec.js b/test/stateFiltersSpec.js index 7f2eb9beb..3141d57ac 100644 --- a/test/stateFiltersSpec.js +++ b/test/stateFiltersSpec.js @@ -25,7 +25,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) { @@ -45,4 +46,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); + })); });