Skip to content

Commit

Permalink
feat($IncludedByStateFilter): add parameters to $IncludedByStateFilter
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cyrilf committed Feb 5, 2015
1 parent 7032281 commit 963f6e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/stateFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion test/stateFiltersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}));
});

0 comments on commit 963f6e7

Please sign in to comment.