$stateProvider .state('member',{ url: '/member/:membersId',templateUrl: 'templates/member.html',resolve : { // From examples for testing simpleObj: function(){ return {value: 'simple!'}; },memberDetails : function(FamilyService,$state) { return FamilyService.getMember($state.current.params.membersId); } },controller: 'MemberController' });
由于文档说$ stateParams不可用,所以我使用$ state.current.params。应该没事。相反,我会死空气。我无法访问membersId来挽救我的生命。@H_502_4@
要测试我的服务,并确保不是问题,我硬编码在一个memberId,控制器获取memberDetails结果以及simpleObj结果。所以,服务和控制器和工作伟大。@H_502_4@
硬编码的例子:@H_502_4@
$stateProvider .state('member',$state) { return FamilyService.getMember('52d1ebb1de46c3f103000002'); } },controller: 'MemberController' });
即使文档说您无法以决定的方式使用$ stateParams,反正我也尝试过。它也不工作。@H_502_4@
返回FamilyService.getMember($ stateParams.membersId);@H_502_4@
在世界上我如何获得成员ID参数,以传递给FamilyService以解决?@H_502_4@
我没有多少头发要拉出来;所以有人救我。@H_502_4@
$stateProvider .state('member',resolve : { simpleObj: function(){ return {value: 'simple!'}; },$stateParams) { return FamilyService.getMember($stateParams.membersId); } },controller: 'MemberController' });
我仍然不明白为什么文档说这是不可能的。@H_502_4@
Two Important $stateParams Gotchas@H_502_4@
The $stateParams object is only populated after the state is activated
and all dependencies are resolved. This means you won’t have access to
it in state resolve functions. Use $state.current.params instead.
$stateProvider.state(‘contacts.detail’,{ resolve: {
someResolve: function($state){
//* We cannot use $stateParams here,the service is not ready //
// Use $state.current.params instead *// return $state.current.params.contactId + “!” }; },// … })@H_502_4@