title: How to store user details for further use in angularjs
body: <p>I am working on web application using angularjs. I need the user's email address throughout my application, how can I store it for further use? </p>
  
  <p>Currently what I am doing is: </p>
  
  <p>I have created a user service </p>
  
  <pre><code>'use strict';
  
  var module = angular.module('moduleName');
  
  module.factory('UserService',['$resource',function($resource){
      var currentUserEmail = null;
      return {
          getUserResource : function(){
              return $resource('users',{email:'@email'});
          },
          saveCurrentUserEmail : function (email){
              currentUserEmail = email;
          },
          getCurrentUserEmail : function (){
              return currentUserEmail;
          }
      };
  }]);
  </code></pre>
  
  <p>At login, I store the user email address using the user service:</p>
  
  <pre><code>UserService.saveCurrentUserEmail($scope.username);
  </code></pre>
  
  <p>Now, when I go to another view, in the controller, the user email is what I expect.</p>
  
  <pre><code>console.debug("Current User email "+UserService.getCurrentUserEmail());
  </code></pre>
  
  <p>Which prints the user's email address</p>
  
  <p>But when I refresh the page with (ctrl+f5). then the current user email is null.</p>
  
  <pre><code>Current User email null
  </code></pre>
  
  <p>What I am doing wrong, or what should I do to save this email address for further use?</p>