Skip to content

Commit 963f6e7

Browse files
committed
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): <div ng-show="'**.foo.**' | includedByState:{id: 'new'}">It works</div> Closes #1735
1 parent 7032281 commit 963f6e7

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/stateFilters.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function $IsStateFilter($state) {
2727
*/
2828
$IncludedByStateFilter.$inject = ['$state'];
2929
function $IncludedByStateFilter($state) {
30-
var includesFilter = function (state) {
31-
return $state.includes(state);
30+
var includesFilter = function (state, params, options) {
31+
return $state.includes(state, params, options);
3232
};
3333
includesFilter.$stateful = true;
3434
return includesFilter;

test/stateFiltersSpec.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ describe('includedByState filter', function() {
2525
$stateProvider
2626
.state('a', { url: '/' })
2727
.state('a.b', { url: '/b' })
28-
.state('c', { url: '/c' });
28+
.state('c', { url: '/c' })
29+
.state('d', { url: '/d/:id' });
2930
}));
3031

3132
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() {
4546
$q.flush();
4647
expect($parse('"a" | includedByState')($rootScope)).toBe(false);
4748
}));
49+
50+
it('should return true if the current state include input state and params', inject(function($parse, $state, $q, $rootScope) {
51+
$state.go('d', { id: 123 });
52+
$q.flush();
53+
expect($parse('"d" | includedByState:{ id: 123 }')($rootScope)).toBe(true);
54+
}));
55+
56+
it('should return false if the current state does not include input state and params', inject(function($parse, $state, $q, $rootScope) {
57+
$state.go('d', { id: 2377 });
58+
$q.flush();
59+
expect($parse('"d" | includedByState:{ id: 123 }')($rootScope)).toBe(false);
60+
}));
4861
});

0 commit comments

Comments
 (0)