.run(['$rootScope', '$state', 'Session', function ($rootScope, $state, Session) {
$rootScope.$on('$stateChangeStart', function (e, toState) {
console.log('inside .run')
if (toState.url == '/') {
e.preventDefault();
if (Session.user) { // and isAdmin == true
$state.go('admin')
} //if isAdmin == false redirect to chat
else {
$state.go('login')
}
} else if (!Session.user && toState.url != '/login') {
e.preventDefault();
$state.go('login')
}
return;
});
}])
This is my .run module and in that i need to initialize a isAdmin
variable which i can change in my controllers and check if isAdmin is
true in every state change and redirect to admin
or chat
page.
i tried adding initializing isAdmin
as $rootScope.isAdmin
in .run()
but before i can fix its value in controller the .run()
throws isAdmin
undefined error.
Can anyone suggest a workaround?
Thanks in advance