【发布时间】:2017-12-22 12:00:26
【问题描述】:
我的应用中有大量 angularjs 路由。我想根据一些用户权限级别设置对这些路由的访问。
angular.module('myApp').run(['$rootScope', 'someAuthFactory', function($rootScope, someAuthFactory) {
$rootScope.$on('$stateChangeStart', function (event, toState) {
$rootScope.permissions = someAuthFactory.getPermssionLevels();
$rootScope.specialRights = $rootScope.permissions.indexOf('superRole') > -1;
...
这是我的一条路线:
.state("dashboard.overview", {
url: "/dashboard",
templateUrl: "app/dashboard.html",
resolve: {
roles: ['rootScope', function (rootScope) {
return $rootScope.specialRights;}]
},
所以这段代码有效,但如果我想添加这个:
resolve: {
roles: ['rootScope', function (rootScope) {
return $rootScope.specialRights;}]
}
到每条路线,都会有重复的代码,或者如果我想查找其他角色,那会很无聊。 我们能否让 resolve 部分更小更清晰?
【问题讨论】:
标签: javascript angularjs angular-ui-router