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

Sim*_*lGy 45 coffeescript angularjs 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.
Run Code Online (Sandbox Code Playgroud)

有什么东西会列出这两个州,component1并且component2

Sim*_*lGy 95

$state.get()

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

如何在ui-router中枚举注册状态?


Jac*_*cka 7

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

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

// => ['/login', '/home', '/something']
Run Code Online (Sandbox Code Playgroud)