如何查看AngularJS / UI-Router中配置的状态?

时间:2014-02-05 23:01:17

标签: angularjs coffeescript angular-ui angular-ui-router

有没有办法查看$stateProvider上设置的所有状态?

在这种情况下,我希望我的状态分配可以分布在许多文件中。我想在另一个文件中检查runconfig上的已建状态。

例如:

# 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.

是否有某些内容会列出两个州component1component2

2 个答案:

答案 0 :(得分:95)

$state.get()

返回所有状态的数组。包括顶级抽象状态,但如果需要,可以将其过滤掉。

How to enumerate registered states in ui-router?

答案 1 :(得分:7)

对于尝试获取实际URL路由(包括正确显示的嵌套状态)的人:

$state.get().map(function(state) { return $state.href(state.name) })

// => ['/login', '/home', '/something']