Skip to content

Commit 987b07e

Browse files
committed
Added $state.getAll to return the entire state table.
1 parent e8ea509 commit 987b07e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/state.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
348348
return (state && state.self) ? state.self : null;
349349
};
350350

351+
$state.getAll = function () {
352+
var list = [];
353+
forEach(states, function(state) { list.push(state.self); });
354+
return list;
355+
};
356+
351357
function resolveState(state, params, paramsAreFiltered, inherited, dst) {
352358
// Make a restricted $stateParams with only the parameters that apply to this state if
353359
// necessary. In addition to being available to the controller and onEnter/onExit callbacks,

test/stateSpec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,32 @@ describe('state', function () {
393393
expect($state.get('A')).toBe(A);
394394
expect($state.get('Z')).toBeNull();
395395
}));
396+
397+
it("should return all of the state's config", inject(function ($state) {
398+
var list = $state.getAll();
399+
var names = [
400+
'', // implicit root state
401+
'A',
402+
'B',
403+
'C',
404+
'D',
405+
'DD',
406+
'E',
407+
'H',
408+
'HH',
409+
'HHH',
410+
'home',
411+
'home.item',
412+
'about',
413+
'about.person',
414+
'about.person.item',
415+
'about.sidebar',
416+
'about.sidebar.item',
417+
'first',
418+
'second'
419+
];
420+
expect(list.map(function(state) { return state.name; })).toEqual(names);
421+
}));
396422
});
397423

398424
describe('url handling', function () {

0 commit comments

Comments
 (0)