Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see what states are configured in AngularJS / UI-Router?

Is there a way to see all of the states that have been set on $stateProvider?

In this case, I would like my state assignments to be distributed across many files. I would like to inspect the built states on run or config in a different file.

For example:

# component1.coffee angular.module('zoo').config ($stateProvider) ->   $stateProvider.state 'component1',     url: '/component1'     template: _template     controller: 'Component1Ctrl'  # component2.coffee angular.module('zoo').config ($stateProvider) ->   $stateProvider.state 'component2',     url: '/component2'     template: _template     controller: 'Component2Ctrl'  # componentNavigation.coffee angular.module('zoo').run ($state) ->   console.log 'All configured states:', $state.configuredStates # doesn't exist. 

Is there something that will list out the two states, component1 and component2?

like image 327
SimplGy Avatar asked Feb 05 '14 23:02

SimplGy


People also ask

What are states in AngularJS?

The STATE in AngularJS is a mechanism that allows us to update the view based on changes to the model. It is a two-way binding between data and DOM elements. Moreover, the State helps us keep track of data that changes over time, such as whether a particular button has been pressed or not.

What is state provider AngularJS?

$stateProvider is used to define different states of one route. You can give the state a name, different controller, different view without having to use a direct href to a route. There are different methods that use the concept of $stateprovider in AngularJS.

What is UI routing in AngularJS?

Angular-UI-Router is an AngularJS module used to create routes for AngularJS applications. Routes are an important part of Single-Page-Applications (SPAs) as well as regular applications and Angular-UI-Router provides easy creation and usage of routes in AngularJS.

What is UI view in AngularJS?

The ui-view directive tells angularJS where to inject the templates your states refer to. When a state is activated, its templates are automatically inserted into the ui-view of its parent state's template. If it's a top-level state—which 'business' is because it has no parent state–then its parent template is index.


2 Answers

$state.get()

returns an array of all states. Includes the top-level abstract state, but you can filter that out if you want.

How to enumerate registered states in ui-router?

like image 171
SimplGy Avatar answered Oct 27 '22 09:10

SimplGy


For people who try to get actual URL routes including properly displayed nested states:

$state.get().map(function(state) { return $state.href(state.name) })  // => ['/login', '/home', '/something'] 
like image 25
Jacka Avatar answered Oct 27 '22 11:10

Jacka