title: AngularJS : How would i return value from factory if the data is fetched with http
body: <p>I have this factory in angular:</p>
  
  <pre><code>'use strict';
  
  angular.module('finansiiApp')
    .factory('transactions', function ($http) {
      var transactions = [];
      $http.get("/api/transactions.json")
        .success(function(data, status){
          transactions = data;
        });
  
      // Public API here
      return {
        getTransactions: function () {
          return transactions;
        },
        addTransaction: function(transaction){
          transactions.push(transaction);
        }
      };
    });
  </code></pre>
  
  <p>This is my controller:</p>
  
  <pre><code>'use strict';
  
  angular.module('finansiiApp')
    .controller('MainCtrl', function ($scope, transactions) {
      $scope.searchText = "";
      $scope.filterPrimanja = $scope.filterTrosoci = true;
      console.log(transactions);
      $scope.transactions = transactions.getTransactions();
      $scope.clicked = function(index){
        console.log(index);
      }
    });
  </code></pre>
  
  <p>Now as you probably guessed, my data in the controller(where i call the getTransactions method) is not updated on success. How would i go about making this work?</p>