title: angular js force.com Javascript remoting
body: <p>I am new to Angular JS and really struggling to get data into my controller from javascript remoting. Has anyone done this before?</p>
  
  <pre><code>Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.Forecasting.Users}',
    new Object(),function(result, event){
      return result
    }
  );
  </code></pre>
  
  <p>How on earth do i get the data into the controller : </p>
  
  <pre><code>var forecastingCtrl = function($scope, $q){
      $scope.lengths = function(){return '5'};
      $scope.users = [];
  }
  </code></pre>
  
  <hr>
  
  <p>EDIT : Following works fine:</p>
  
  <pre><code>fc.service('Users', function($rootScope, $q) {
      this.get = function(){
          var deferred = $q.defer();
  
              Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.Forecasting.Users}',new Object(),function(result, event){
                  if(event) {
                       $rootScope.$apply(function() {
                          deferred.resolve(result);
                      });
  
                  } else { 
                      deferred.reject(result);
                  }            
              });
              return deferred.promise;
  
      }
  
  });
  
  function forecastingCtrl($scope, $q, Users){
      $scope.lengths = function(){return '5'};
  
  
      var promise = Users.get();
      promise.then(
          function(users){
              $scope.users = users;
          },
          function(reason){
              alert('Failed: ' + reason);
          }
      );    
  
  };
  </code></pre>