title: Use Promise and service together in Angular
body: <p>My question is based on <a href="https://groups.google.com/forum/#!msg/angular/qagzXXhS_VI/p9ArYjfivW8J" rel="noreferrer">this topic</a> in Angular Google group.<br>
  I want to provide a service which stores some basic data retrieved from the backend via $http, then I only need to fetch those data once. like,  </p>
  
  <pre><code>var load = function() {
     return $http.get(...).then(function(data) {
         return data.user; 
     });
  };
  
  module.factory("userProvider", function() {
      var user;
      var getUser = function() {
          if(!user) {
              load().then(function(data) {
                 user = data;
             });
          }
          return user;
      };
      return {
          getUser : getUser
      }
  });
  
  module.controller("UserController", ["userProvider", function UserController("userProvider") {
      var user = userProvider.getUser();
      // do something with user
  }]);
  </code></pre>
  
  <p>The problem is that the promise chain ends in userProvider but not in controller, so the user is undefined the first time I use this controller  since the data has not been returned.  </p>
  
  <p>How can I use such a storage service and return the data correctly? Thanks!</p>