Skip to content

Commit 243716e

Browse files
committed
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): <div ng-show="'**.foo.**' | includedByState:{id: 'new'}">It works</div> Related doc: http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state#methods_includes
1 parent 62a4609 commit 243716e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/state/stateFilters.ts

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

test/stateFiltersSpec.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ describe('includedByState filter', function() {
2828
$stateProvider
2929
.state('a', { url: '/' })
3030
.state('a.b', { url: '/b' })
31-
.state('c', { url: '/c' });
31+
.state('c', { url: '/c' })
32+
.state('d', { url: '/d/:id' });
3233
}));
3334

3435
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() {
4849
$q.flush();
4950
expect($parse('"a" | includedByState')($rootScope)).toBe(false);
5051
}));
52+
53+
it('should return true if the current state include input state and params', inject(function($parse, $state, $q, $rootScope) {
54+
$state.go('d', { id: 123 });
55+
$q.flush();
56+
expect($parse('"d" | includedByState:{ id: 123 }')($rootScope)).toBe(true);
57+
}));
58+
59+
it('should return false if the current state does not include input state and params', inject(function($parse, $state, $q, $rootScope) {
60+
$state.go('d', { id: 2377 });
61+
$q.flush();
62+
expect($parse('"d" | includedByState:{ id: 123 }')($rootScope)).toBe(false);
63+
}));
5164
});

0 commit comments

Comments
 (0)