title: AngularJS $http return value
body: <p>I am new to <code>AngularJS</code> and only aware of the basics of AngularJS. I want to return a value from  <code>$http</code>. That is <code>$http</code> should return a value to the global variable of My Application.</p>
  
  <p>I have tried this:</p>
  
  <pre><code>var sessionValues = null;
  var AdminController = angular.module('AdminController', []);
  
  AdminController.controller('LoginController', ['$scope', '$http','$location',
  function ($scope, $http, $location){
  $http({
          method: "post",
          url: "API/MyPage.php",
          headers: {'Content-Type': 'application/x-www-form-urlencoded'}
      }).success(function(data){
          sessionValues = eval(data);
          console.log(sessionValues); /*Returns desired string*/
      }).error(function(){
          $scope.message="Some error has occured";
      });
      console.log(sessionValues); /*Returns null */
    }
  ]);
  </code></pre>
  
  <p>I tried using <code>$rootScope</code>, but was not successful.</p>
  
  <p>I understand that this is because it is an asynchronous call, but how can I fetch the value in JS's global variable.?</p>
  
  <p>Can anyone help me about this.?</p>