I want to make an $http.post
inside another $http.post
as the second one is dependant on the first. Basically what I'm doing is:
$http.post("/my/server/location").then(function (response) {
$http.post("/my/second/api/call/"+response.data.number).then(function (response) {
$scope.message = "Created successfully";
}, function (response){
$scope.message = "Could not create";
});
//Create modal from response.data received from first API Call
//Add $scope.message to this modal.
});
What's happening as you would have guessed is the second one stays pending until the initial promise is returned, and I want to show $scope.message
in the modal which is hence, not possible. While I understand why that's happening, I can't seem to figure how to get around that. I tried dealing with $q
but made a mess out of it. Any help will be gladly appreciated.