当前位置: 首页 > 面试题库 >

如何查看在AngularJS / UI-Router中配置了哪些状态?

章承
2023-03-14
问题内容

有没有办法查看所有已设置的状态$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


问题答案:

$state.get()

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

如果您查看$state.get()最新版本的ui-router 的文档,则会注意到不向函数传递任何参数应返回所有已配置状态对象的数组。

/**
 * @ngdoc function
 * @name ui.router.state.$state#get
 * @methodOf ui.router.state.$state
 *
 * @description
 * Returns the state configuration object for any state by passing the name
 * as a string. Without any arguments it'll return a array of all configured
 * state objects.
 *
 * @param {string|object} stateOrName The name of the state for which you'd like 
 * to get the original state configuration object for.
 * @returns {object} State configuration object or array of all objects.
 */


 类似资料:
  • 问题内容: 我的ui路由器状态提供程序中具有以下状态: 这遵循具有默认子状态的最佳做法,如ui-router文档中此处所述。 但是,当我现在在文档中的某处引用父级的链接时,例如,我总是收到一条错误消息,说我无法转换为抽象状态。当我在地址栏中手动输入URL并按Enter时,一切正常。 相关Plunker:http ://plnkr.co/edit/d3Z0tOwC3VCTPqGiB0df?p=pre

  • 问题内容: 在不使用服务或在父控制器中构造观察器的情况下,如何使子状态访问主控制器的。 我无法在子状态下访问mainController范围-而是正在获取该范围的另一个实例- 不是我想要的。我觉得我缺少一些简单的东西。在状态对象中有一个共享的数据配置选项,但是我不确定是否应该将其用于这样的事情。 问题答案: 我创建了工作的插件,展示了如何使用和UI- Router。 状态定义未更改: 但是每个状态

  • 问题内容: 考虑从ui-router文档获取的以下状态: 以及状态“ state1”的“ partials / state1.html”控制器: 是否有任何内置功能可从控制器内部或模板内部确定控制器/模板与哪个状态关联? 例如: 而且,如果没有内置解决方案,您将如何“装饰” $ state或$ stateParams以包含此信息? 我想出的唯一解决方案是使用$ state.get(),然后使用控制

  • 问题内容: 我如何在PHP 中检查是否选中a ? 问题答案: 如果选中该复选框,则将传递该复选框的值。否则,该字段不会在HTTP帖子中传递。

  • 通过sysconstraints只能看到一个{tab_id}_{id}字符串. 无法确认这个主键用了哪些列

  • 在Liferay IDE中创建portlet时,我已将其配置为具有Liferay的配置模式。作为回应,wizart创建了包含以下文本的JSP文件: 如何从Liferay调用此页面查看此文本?单击扳手图标并选择时,我看不到类似的内容。 更新 路径设置正确,因为它是由向导设置的。 问题是如何通过鼠标从Web界面调用这个JSP?