如何在使用angularjs注销后清除本地存储

如何在使用angularjs注销后清除本地存储,angularjs,Angularjs,Html代码 <div><a href="#/logout"><h2>Log Out</h2></a></div> app.controller('LogoutController',function($location,$scope){ $location.path('/'); }); app.service('loginService', [ '$http', function($http) {

Html代码

<div><a href="#/logout"><h2>Log Out</h2></a></div>
app.controller('LogoutController',function($location,$scope){
        $location.path('/');
});
app.service('loginService', [ '$http', function($http) {

    this.get = function(path) {
        var data = $http.get(path).then(function(response) {
            return response.data;
        });
        return data;
    };

} ]);
注销控制器

<div><a href="#/logout"><h2>Log Out</h2></a></div>
app.controller('LogoutController',function($location,$scope){
        $location.path('/');
});
app.service('loginService', [ '$http', function($http) {

    this.get = function(path) {
        var data = $http.get(path).then(function(response) {
            return response.data;
        });
        return data;
    };

} ]);
它工作正常,注销后进入登录页面,如果我按下后退按钮,它也不会重定向到最后一页,但我认为这不是我工作的正确方式,我在注销时没有清除本地存储,我坚持如何通过注销清除本地存储值,请帮助我我是angularjs新手

将值设置为本地存储的登录控制器

 $scope.login = function () {
         $scope.empData=[]

         $scope.empData = loginService.get('http://183.1.1/HospitalManagementSystem/Service1.svc/LoginVerification/' + $scope.emailId + '/' + $scope.password);

         $scope.empData.then(function (empData) {
             console.log( $scope.empData)
             /*if (empData !== undefined && empData !== null){
                 if(empData._statusCode === constants.statusCode) {*/
                     if (empData.LoginVerificationResult.length === 0) {
                        console.log('Employee details are not Available');
                     } else {
                         $rootScope.name=empData.LoginVerificationResult[0].UserName;


                         localStorage.setItem("Role ID",empData.LoginVerificationResult[0].RoleID);
                         localStorage.setItem("UserId",empData.LoginVerificationResult[0].UserId);
                         localStorage.setItem("UserName",empData.LoginVerificationResult[0].UserName);                      
                                   $location.path('/welcome')
                     }
         });
     };
登录服务

<div><a href="#/logout"><h2>Log Out</h2></a></div>
app.controller('LogoutController',function($location,$scope){
        $location.path('/');
});
app.service('loginService', [ '$http', function($http) {

    this.get = function(path) {
        var data = $http.get(path).then(function(response) {
            return response.data;
        });
        return data;
    };

} ]);

我想您只需要一个
localStorage.clear()

app.controller('LogoutController',function($location, $scope, $window){
    $window.localStorage.clear();
    $location.path('/');
});

你在用这个还是什么?@Michelem不,我没用你在用什么?请添加相关代码。嗨@Michelem我又添加了我的代码,什么是
localStorage
?谢谢@Michelem我得到了答案