问题描述
如果我有一个抽象状态:
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.yand 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 })">Go to drug.x for {{ scopeVariable }}</a>
这篇关于在抽象状态,UI路由器,angularjs的url中的stateParams的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!