Skip to content

Commit 4da7e59

Browse files
committed
Merge pull request #2269 from philBrown/patch-1
feat: support params in isState filter
2 parents 07c046c + 71d7469 commit 4da7e59

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
@@ -9,8 +9,8 @@
99
*/
1010
$IsStateFilter.$inject = ['$state'];
1111
function $IsStateFilter($state) {
12-
var isFilter = function (state) {
13-
return $state.is(state);
12+
var isFilter = function (state, params) {
13+
return $state.is(state, params);
1414
};
1515
isFilter.$stateful = true;
1616
return isFilter;

test/stateFiltersSpec.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ describe('isState filter', function() {
33
beforeEach(module(function($stateProvider) {
44
$stateProvider
55
.state('a', { url: '/' })
6-
.state('a.b', { url: '/b' });
6+
.state('a.b', { url: '/b' })
7+
.state('with-param', { url: '/with/:param' });
78
}));
89

910
it('should return true if the current state exactly matches the input state', inject(function($parse, $state, $q, $rootScope) {
@@ -17,6 +18,18 @@ describe('isState filter', function() {
1718
$q.flush();
1819
expect($parse('"a" | isState')($rootScope)).toBe(false);
1920
}));
21+
22+
it('should return true if the current state and param matches the input state', inject(function($parse, $state, $q, $rootScope) {
23+
$state.go('with-param', {param: 'a'});
24+
$q.flush();
25+
expect($parse('"with-param" | isState: {param: "a"}')($rootScope)).toBe(true);
26+
}));
27+
28+
it('should return false if the current state and param does not match the input state', inject(function($parse, $state, $q, $rootScope) {
29+
$state.go('with-param', {param: 'b'});
30+
$q.flush();
31+
expect($parse('"with-param" | isState: {param: "a"}')($rootScope)).toBe(false);
32+
}));
2033
});
2134

2235
describe('includedByState filter', function() {

0 commit comments

Comments
 (0)