diff --git a/src/state.js b/src/state.js index 8020876a6..a2717bd37 100644 --- a/src/state.js +++ b/src/state.js @@ -344,6 +344,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $ }; $state.get = function (stateOrName) { + if (!isDefined(stateOrName)) { + var list = []; + forEach(states, function(state) { list.push(state.self); }); + return list; + } var state = findState(stateOrName); return (state && state.self) ? state.self : null; }; diff --git a/test/stateSpec.js b/test/stateSpec.js index 02b180a96..2f433e41a 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -393,6 +393,32 @@ describe('state', function () { expect($state.get('A')).toBe(A); expect($state.get('Z')).toBeNull(); })); + + it("should return all of the state's config", inject(function ($state) { + var list = $state.get().sort(function(a, b) { return (a.name > b.name) - (b.name > a.name); }); + var names = [ + '', // implicit root state + 'A', + 'B', + 'C', + 'D', + 'DD', + 'E', + 'H', + 'HH', + 'HHH', + 'about', + 'about.person', + 'about.person.item', + 'about.sidebar', + 'about.sidebar.item', + 'first', + 'home', + 'home.item', + 'second' + ]; + expect(list.map(function(state) { return state.name; })).toEqual(names); + })); }); describe('url handling', function () {