I have a controller that deals with navigation bar (user staff etc.) that wraps all other controllers in my code.
<div class="container" ng-controller="wrapCtrl">
... navbar...
<div ng-view></div>
</div>
Basically I want to keep the navbar on top throughout the script and it will contain view links and handle some user related functions. This has caused me a lot of trouble since everything else (login, dashboard) etc. have their own controllers. Updating the navbar in sync with other controllers is quite problematic. Now I am struggling with my logout function which is handled in wrapCtrl. Logout function simply removes tokens and redirects the user to login page with $location.path('/login'). The the thing is, when location change fires in parent controller (being wrapCtrl), child controller (which is dashboard controller) reinitializes before the actual redirection. Since the user is logged out during location change, this reinitialization causes all the functions in dashboard controller to go mad. I don't think it is necessary but I get flamed if I don't do it so here is the logout function
$scope.logout = function logout() {
if (AuthenticationService.isLogged) {
localStorageService.remove('token');
UserInfoService.setUsrName("");
$location.path("/login");
}
}
Is this supposed to be so problematic as it is now? Or is this (nested controllers?) not the right way to handle my situation? I am aware of the ui-router. But I want to know if this is solvable without using yet another module.