抽象状态、ui

编程入门 行业动态 更新时间:2024-10-28 02:22:34
本文介绍了抽象状态、ui-router、angularjs url 中的 stateParams的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

如果我有一个抽象状态:

if i have an abstract state:

$stateProvider.
        state('drug', {
            abstract: true,
            url: '/drug/:drugId',
            template:
            '<ui-view></ui-view>',
            resolve: {
                drugId : ['$stateParams', function($stateParams){
                    return $stateParams.drugId;
                }]
            }
        }

有一些子状态,形式为:drug.x,drug.y我想在应用程序的一个地方选择一个 DrugId,它会通过抽象状态到达所有子状态,这样之后当我调用drug.x"状态时,它就会有 drugId 值——我在哪里以及如何使用 drugId 参数调用药物状态?我知道我不能调用抽象状态本身.

that have some child states, in form: drug.x,drug.y and I want to choose, in one place in the app, a drugId that will come through the abstract state to all the child states, so that after that when i call to 'drug.x' state, it'll have the drugId value - where and how i do this one call to drug state with drugId param? I know that I can't call the abstract state itself.

谢谢.

推荐答案

通过将 $stateParams.drugId 作为解析公开,您已经完成了棘手的部分.现在你只需像这样将它注入你的子状态控制器:

You have already done the tricky part by exposing $stateParams.drugId as a resolve. Now you just inject it into your substate controller like so:

$stateProvider.state('drug.x', {
  controller: function(drugId) { } // drugId is injected from the resolve you defined in 'drug'
}

要将参数提供给 drug.x,您只需将其添加到转换参数:

To provide the parameter to drug.x, you simply add it to the transition parameters:

$state.go('drug.x', { drugId: 123 });

<a ui-sref="drug.x({ drugId: scopeVariable })">转到 drug.x 获取 {{ scopeVariable }}</a>

这篇关于抽象状态、ui-router、angularjs url 中的 stateParams的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 04:23:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/996183.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:抽象   状态   ui

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!