【问题标题】:How to see what states are configured in AngularJS / UI-Router?如何查看 AngularJS / UI-Router 中配置了哪些状态?
【发布时间】:2014-03-02 15:56:24
【问题描述】:

有没有办法查看在$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 这两个状态?

【问题讨论】:

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


【解决方案1】:

$state.get()

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

How to enumerate registered states in ui-router?

【讨论】:

    【解决方案2】:

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

    $state.get().map(function(state) { return $state.href(state.name) })
    
    // => ['/login', '/home', '/something']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-03
      • 1970-01-01
      • 2010-12-14
      • 2014-12-15
      • 2014-12-11
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多