title: how to clear local storage after logout using angularjs
body: <p><strong>Html code</strong> </p>
  
  <pre><code>&lt;div&gt;&lt;a href="#/logout"&gt;&lt;h2&gt;Log Out&lt;/h2&gt;&lt;/a&gt;&lt;/div&gt;
  </code></pre>
  
  <p><strong>My routing</strong></p>
  
  <pre><code> app.config([ '$routeProvider', function($routeProvider) {
  
      $routeProvider.when('/', {
          templateUrl : 'app/components/login/Login.html',
          controller : 'loginCtrl'
  
      }).when('/register/', {
          templateUrl : 'app/components/register/register.html',
          controller : 'registerController'
      }).when('/welcome/', {
          templateUrl : 'app/components/welcome/welcome.html',
          controller : 'welcomeController'
      }).when('/home', {
          templateUrl : 'app/components/home/home.html',
          controller : 'homeController'
      }).when('/homeView', {
          templateUrl : 'app/components/home/homeView.html',
          controller : 'homeController'
      }).when('/graph', {
          templateUrl : 'app/components/home/graphView.html',
          controller : 'LineCtrl'
      }).when('/logout', {
          templateUrl : 'app/components/login/Login.html',
          controller : 'logoutCtrl'
      }).otherwise({
          redirectTo : "/"
      });
  } ]);
  </code></pre>
  
  <p><strong>Logout Controller</strong> </p>
  
  <pre><code>app.controller('LogoutController',function($location,$scope){
          $location.path('/');
  });
  </code></pre>
  
  <p>It is working fine and after logout it goes to login page and if i press back button also it will not redirect to last page but i think this not the right way i am working  and i am not clearing the local storage while logout,I stuck with how to clear the local storage values with logout, Please help me i am new to angularjs</p>
  
  <p><strong>login controller in which values are set to localstorage</strong></p>
  
  <pre><code> $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 &amp;&amp; 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')
                       }
           });
       };
  </code></pre>
  
  <p><strong>LoginService</strong> </p>
  
  <pre><code>app.service('loginService', [ '$http', function($http) {
  
      this.get = function(path) {
          var data = $http.get(path).then(function(response) {
              return response.data;
          });
          return data;
      };
  
  } ]);
  </code></pre>