title: How to use $scope value from one HTTP request in another HTTP request
body: <p>I am using AngularJS to send form data to the server.</p>
  
  <pre><code>app.controller("OrganizerReg", ["$scope","$http", function($scope,$http) {
  
  
  $scope.userOrganizer = {};
  
  
  $scope.processform = function() {
  
      $http ({
  
              method: 'POST',
              url: 'http://52.11.67.77:3000/api/users',
              headers: {'Content-Type': 'application/json'},
              data: JSON.stringify($scope.userOrganizer)
      })
          .success(function(response) {
              console.log(response.user_id);
              $scope.user_id = response.user_id;
      })
  
  
      $http ({
  
          method: 'POST',
          url : 'http://52.11.67.77:3000/api/users/'+$scope.user_id+'/accessTokens',
  
  
      })
          .success(function(response) {
  
              console.log(response);
          })
  
  
  }
  </code></pre>
  
  <p>In order to get access Token , I need to send a POST request.The response from first HTTP request , gives the <code>user_id</code> which is needed for generating the access token. The problem is whenever I send the request, the <code>$scope.user_id</code> returns undefined in the header. How to set my <code>$scope.user_id</code> global, so that it can be used by another HTTP request.</p>
  
  <p><strong>EDIT</strong>
  I read the <a href="https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call">duplicate question</a> but it still hasn't helped me.</p>