I have this navigation:
<ul class="dropdown-menu m-t-xs compact" style="float:right !important;right: 0px;">
<li ng-hide="$state.includes('root.projects')"><a ui-sref="portal.user_settings"><span class="icon glyphicon glyphicon-user"></span>User Settings</a></li>
<li ng-show="$state.includes('root.projects')"><a ui-sref="root.user_settings"><span class="icon glyphicon glyphicon-user"></span>User Settings</a></li>
<li class="divider"></li>
<li ng-controller="LoginCtrl"><a href="" ng-click="logout"><span class="icon glyphicon glyphicon-log-out"></span>Logout</a></li>
</ul>
But when I click the logout link, nothing happens.
Here is my controller:
'use strict';
function LoginCtrl($scope, Authentication, $window, $cookies, $http, $location) {
var _self = this;
_self.loginProcessing = false; //This is a flag for showing the loader animation while the wait for the login response.
_self.error = null;
_self.login = function(vm) { //Defines the login function as a variable on the LoginCtrl
_self.loginProcessing = true;
Authentication.Login(vm.email, vm.password).then(function(data){
_self.loginProcessing = false;
$window.sessionStorage['currentUser'] = JSON.stringify(data);
$location.path("/projects");
}).catch(function(err) {
_self.error = true;
_self.loginProcessing = false;
});
}
_self.logout = function() {
alert("CLICKED");
// Authentication.logout().then(function() {
// $window.sessionStorage['currentUser'] = null;
//
// $location.path("/login");
// });
}
}
angular.module('controllers').controller('LoginCtrl', LoginCtrl);
And here is the configured route:
.state('logout',{
url: "/logout",
controller: "LoginCtrl",
templateUrl: 'views/logout.html',
})
I am 100% new to AngularJS, so please excuse my ignorance. Thanks!
controllerAsin view. How are controllers assigned to view?controlleroption in the route to beLoginCtrl as LoginCtrland it's still not working. I'm not sure if that's what you mean