如何根据角色查看菜单?
此代码正常运行,但我发现问题$role_id
仅在刷新代码后设置。没有重新加载就无法分配。
angular.module('main', [])
.config(routeConfig);
function routeConfig($stateProvider,$rootScope)
{
angular.injector(['ngCookies'])
.invoke(['$cookies','$cookieStore', function($cookies,$cookieStore)
{
$role_id = $cookieStore.get('rolecookies');
console.log($role_id);
if($rootScope.role_id==1)
{
$stateProvider
.state('main.admin',
{
url: '/admin',
controller: 'psCtrl',
templateUrl: 'app/pages/admin/main/main.view.html',
title: 'Admin',
sidebarMeta: {
icon: 'ion-android-home',
order: 1,
},
})
.state('main',
{
url: '/main',
template : '<ui-view></ui-view>',
abstract: true,
title: 'Main Home',
sidebarMeta: {
icon: 'ion-android-home',
order: 1,
},
});
}
}]);
}
答案 0 :(得分:0)
我认为您的Cookie已设置,请尝试
<!-- -->
<body ng-init="getCookie()">
$scope.getCookie = function(){
$role_id = $cookieStore.get('rolecookies');
//I'm not familiar with NgCookies but this is what I mostly workaround with it when avoiding refresh
}