title: Getters return null in Angular Factory methods
body: <p>I have the following factory and when I call the setters, from controller function, it sets the name but if I call the getters from controller, it returns null. Why the variables values are not showing up?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>(function () {
      'use strict';
  
      angular
          .module('myapp')
          .factory('myFactory', ServiceFactory);
  
      myFactory.$inject = ['$http', '$rootScope'];
      var config = {
          // TO DO : check if anything required
      };
   
   
  
      /* @ngInject */
      function myFactory($http, $rootScope) {
   
   var userName = null;
   var userId = null;
   var pwd = null;
   
   var service = {
              
              getUserName: getUserName,
              setUserName: setUserName,
     getPwd:getPwd,
              setPwd:setPwd,
            
          };
    function getUserName() {
              console.log("user name.getUserName." + userName);
              return userName;
          }
  
          function setUserName(userName) {
              console.log("user name.." + userName);
              userName = userName;
          }
  
         
          function getPwd() {
              console.log("user getPwd.." + pwd);
              return pwd;
          }
  
          function setPwd(pwd) {
              console.log("user setPwd.." + pwd);
              pwd = pwd;
          }
    
    return service;
   }
  })();</code></pre>
  </div>
  </div>
  </p>