title: Angular js returning undefined object from factory
body: <p>I have a controller and factory defined as below.</p>
  
  <pre><code>myApp.controller('ListController', 
          function($scope, ListFactory) {
      $scope.posts = ListFactory.get();
      console.log($scope.posts);
  });
  
  myApp.factory('ListFactory', function($http) {
      return {
          get: function() {
              $http.get('http://example.com/list').then(function(response) {
                  if (response.data.error) {
                      return null;
                  }
                  else {
                      console.log(response.data);
                      return response.data;
                  }
              });
          }
      };
  });
  </code></pre>
  
  <p>What confuses me is that I get the output undefined from my controller, and then the next line of console output is my list of objects from my factory. I have also tried changing my controller to </p>
  
  <pre><code>myApp.controller('ListController', 
          function($scope, ListFactory) {
      ListFactory.get().then(function(data) {
          $scope.posts = data;
      });
      console.log($scope.posts);
  });
  </code></pre>
  
  <p>But I receive the error </p>
  
  <pre><code>TypeError: Cannot call method 'then' of undefined
  </code></pre>
  
  <p>Note: I found this information on using a factory through <a href="http://www.benlesh.com/2013/02/angularjs-creating-service-with-http.html" rel="noreferrer">http://www.benlesh.com/2013/02/angularjs-creating-service-with-http.html</a></p>