更新时间:2023-02-20 15:51:11
不像您那样,您的用户和数据工作正常,特别是因为我有一项服务可以为我提供已登录或未登录的用户以及在这种情况下的所有数据将执行以下操作
Not like you your user and data work, especially as I have a service that gives me the user who is logged in or not, and all data in this case will do the following
您必须做的是在运行"中为不同角色定义变量的值,如下所示:
What you must do is within the "run" define the value of your variable for different roles something like this:
angular.module('starter.controllers', [])
.run(function($window, $rootScope, sessionService) {
var user = sessionService.get('user');
if(user.role == 'Admin'){
$rootScope.adminHeader=true;
}else{
$rootScope.adminHeader=false;
}
})
我的sessioService服务
My sessioService service
.factory('sessionService', ['$http', function($http) {
return {
set: function(key, value) {
return localStorage.setItem(key, JSON.stringify(value));
},
get: function(key) {
return JSON.parse(localStorage.getItem(key));
},
destroy: function(key) {
return localStorage.removeItem(key);
},
};
}])
HTML代码:
<ion-nav-bar ng-class="positive : adminHeader, other_class : !adminHeader">