Skip to content

feat: support params in isState filter #2269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/stateFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
$IsStateFilter.$inject = ['$state'];
function $IsStateFilter($state) {
var isFilter = function (state) {
return $state.is(state);
var isFilter = function (state, params) {
return $state.is(state, params);
};
isFilter.$stateful = true;
return isFilter;
Expand Down
15 changes: 14 additions & 1 deletion test/stateFiltersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ describe('isState filter', function() {
beforeEach(module(function($stateProvider) {
$stateProvider
.state('a', { url: '/' })
.state('a.b', { url: '/b' });
.state('a.b', { url: '/b' })
.state('with-param', { url: '/with/:param' });
}));

it('should return true if the current state exactly matches the input state', inject(function($parse, $state, $q, $rootScope) {
Expand All @@ -17,6 +18,18 @@ describe('isState filter', function() {
$q.flush();
expect($parse('"a" | isState')($rootScope)).toBe(false);
}));

it('should return true if the current state and param matches the input state', inject(function($parse, $state, $q, $rootScope) {
$state.go('with-param', {param: 'a'});
$q.flush();
expect($parse('"with-param" | isState: {param: "a"}')($rootScope)).toBe(true);
}));

it('should return false if the current state and param does not match the input state', inject(function($parse, $state, $q, $rootScope) {
$state.go('with-param', {param: 'b'});
$q.flush();
expect($parse('"with-param" | isState: {param: "a"}')($rootScope)).toBe(false);
}));
});

describe('includedByState filter', function() {
Expand Down