I get $ rootScope undefined when using it from inside $ urlRouterProvider.otherwise.
My goal is to check if the user is currently running or not, during login I set the variable to rootScope.
Interestingly, if I make $ rootScope the first argument, then I will start to get an error for $ injector.
$urlRouterProvider.otherwise(function ($injector, $location, $rootScope) {
console.log("Otherwise Executed");
try {
var $state = $injector.get("$state");
toastr.options.positionClass = "toast-top-full-width";
toastr["error"]($location.$$path + ", Page not Found, names are case sensitive !");
toastr.options.positionClass = "toast-top-right";
if (typeof $rootScope.currentUser === 'undefined')
$state.go("Login");
else
$state.go("dashboard");
} catch (e) {
return "/login"
}
});
source
share