I am using AngularJS to send form data to the server.
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);
})
}
In order to get access Token , I need to send a POST request.The response from first HTTP request , gives the user_id
which is needed for generating the access token. The problem is whenever I send the request, the $scope.user_id
returns undefined in the header. How to set my $scope.user_id
global, so that it can be used by another HTTP request.
EDIT I read the duplicate question but it still hasn't helped me.