单击注销按钮后,相关控制器不会调用,因此注销活动永远不会发生。
我已经使用AngularJs和Spring boot and Security编写了一个登录页面,该页面在登录的情况下可以正常工作,但注销不起作用。
我刚刚粘贴了文件和页面的相关部分。
index.html
<nav class="navbar navbar-default">
<div class="container-fluid">
<div ng-show="authenticated">
<a href="#/"
class="btn btn-info navbar-btn"
role="button">
Home
</a>
<a href="#/register-new-user"
class="btn btn-info navbar-btn"
role="button">
Register New User
</a>
<a href="#/list-all-users"
class="btn btn-info"
role="button">
List All Users
</a>
**<a href="#/logout"
class="btn btn-danger navbar-btn pull-right"
role="button">Logout
</a>**
</div>
</div>
</nav>
app.js删除已写入的URL
.when('/login',{
templateUrl : '/login/login.html',
controller : 'loginController'
})
**.when('/logout',{
templateUrl : '/login/login.html',
controller : 'logoutController'
})**
.otherwise({
redirectTo : '/login'
});
controller.js将请求发布到Spring Security。
app.controller('logoutController', function($rootScope, $scope, $http, $location, $route){
console.log("inside of logout controller...");
$scope.logout = function() {
$http.post('logout', {}).finally(function() {
$rootScope.authenticated = false;
$location.path("/");
});
}
});
答案 0 :(得分:0)
删除封闭功能,以便在路由器实例化控制器时立即执行POST请求:
app.controller('logoutController', function($rootScope, $scope, $http, $location, $route){
console.log("inside of logout controller...");
̶$̶s̶c̶o̶p̶e̶.̶l̶o̶g̶o̶u̶t̶ ̶=̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶(̶)̶ ̶{̶
$http.post('logout', {}).finally(function() {
$rootScope.authenticated = false;
$location.path("/");
});
̶}̶
});