【问题标题】:access data from a state with ui-router使用 ui-router 从状态访问数据
【发布时间】:2015-11-08 12:18:44
【问题描述】:

我会尽量保持简单,同时不会丢失问题的上下文。

假设我有一个使用 ui-router 的状态

$stateProvider.state("home", {
    abstract: true,
    templateUrl: "...",
    meta: {
        label: "...",
        ...
    }
});

如何访问当前状态的meta 对象的属性和值,以便将它们应用到视图中,例如:

<section class="content-header">
    <h1>
        {{meta.label}}
    </h1>
</section>

因此,上面的示例将显示来自当前状态的meta 对象的label 的值。

【问题讨论】:

标签: angularjs angular-ui-router


【解决方案1】:

按照ui-router doc,您应该能够通过注入 $state 并使用它来访问它:

$state.current.meta.label

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    相关资源
    最近更新 更多