title: AngularJS factory not working
body: <p>I have abstracted my working code from a controller into a factory, but it doesn't seem to be working and I can't find what's wrong. I opted for a factory rather than a service because I wanted to execute some code that defined the variable before returning that variable; I want to get <code>result.station</code> (a part of the data returned by the API), not the full result.</p>
  
  <p>This is my code:</p>
  
  <pre><code>var app = angular.module("myApp", []);
  
  app.factory('api', ['$http',
    function($http) {
      var station_list = [];
      $http({
        method: 'GET',
        url: 'http://api.irail.be/stations/?format=json&amp;lang=nl'
      })
        .success(function(result) {
          station_list = result.station;
        });
  
      return {
        Stations: function() {
          return station_list;
        }
      };
  
    }
  ]);
  
  app.controller("myController", ['api', '$scope',
    function(api, $scope) {
      $scope.station_list = api.Stations();
      $scope.title = "Stations";
    }
  ]);
  </code></pre>
  
  <p>and <a href="http://plnkr.co/edit/rYGrpokcQY9qzsf8MiMa?p=preview" rel="nofollow">a working example</a>.</p>