Javascript UI路由器:我可以在子状态下解析父承诺吗?
我正在做一个社交应用程序,它在个人资料页面有一个封面。“编辑”和“访问”页面都有封面,但有不同的子部分。 问题是,封面上显示的一些控制器严格取决于您当前访问的部分 为了解决这个问题,我尝试在父状态的resolve部分返回一个承诺,然后在不同的子状态中解析该承诺Javascript UI路由器:我可以在子状态下解析父承诺吗?,javascript,angularjs,angular-ui-router,Javascript,Angularjs,Angular Ui Router,我正在做一个社交应用程序,它在个人资料页面有一个封面。“编辑”和“访问”页面都有封面,但有不同的子部分。 问题是,封面上显示的一些控制器严格取决于您当前访问的部分 为了解决这个问题,我尝试在父状态的resolve部分返回一个承诺,然后在不同的子状态中解析该承诺 .state('profile', { url: '/profile', controller: 'ProfileController', templateUrl: 'components/profile/prof
.state('profile', {
url: '/profile',
controller: 'ProfileController',
templateUrl: 'components/profile/profile.html',
resolve: {
actor: function(UserService){
return UserService.getUser();
},
target: function($q){
var deferred = $q.defer();
return deferred.promise;
}
}
})
.state('profile.view', {
url: '/:userId',
templateUrl: 'components/profile/view.html',
navbar: true,
parent: 'profile',
resolve: {
/**
*
* @param target
* @param {UserService} UserService
*/
target: function(target, UserService){
target.resolve(UserService.getActions('view'));
}
}
})
不幸的是,我的逻辑有点错误,因为配置文件状态中的返回deletred.promise
阻塞了应用程序
谁能帮我找出我做错了什么
最好的 返回对解析器功能的承诺
.state('profile.view', {
url: '/:userId',
templateUrl: 'components/profile/view.html',
navbar: true,
parent: 'profile',
resolve: {
/**
*
* @param target
* @param {UserService} UserService
*/
target: function(target, UserService){
return UserService.getActions('view').$promise;
}
}
})
这个答案假设
UserService
是一个$resource
查询。其他API返回的承诺不同,但原则相同返回对解析器函数的承诺。我是否也必须从配置文件
状态中删除承诺?