title: AngularJS factory http returns empty
body: <p>I'm trying AngularJS for the first time. I'm getting JSON data from a http-get request using a factory, but the object is returned empty, before the ajax-request is done.</p>
  
  <p>Factory:</p>
  
  <pre><code>myDemo.factory('photosFactory', function($http) {
      var photos = [];
  
      var factory = {};
  
      factory.getPhotos = function() {
          $http({
              url: 'content/test_data.json',
              method: 'GET'
          }).success(function(data, status, headers, config) {
              photos = data;
              return photos;
          });
      };
      return factory;
  });
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>controllers.AppCtrl = function($scope, $location, $http, photosFactory) {
      $scope.photos = [];
      init();
      function init() {
          $scope.photos = photosFactory.getPhotos();
      }
  };
  </code></pre>
  
  <p>This is what I've come up with. When the controller set $scope.photos, the value is empty as if it returns the photos array before it get populated with the ajax response.</p>