Issue
I have an http post to a file which returns a json then i use .then(function(response){}.... but how i cant get another http post that happens in a row and then procceed with the second .then? i want something like
$http({
method:"POST",
url:"....",
data:{'....}).then(function(response){...})
$http({
method:"POST",
url:"....",
data:{'....}).then(function(response){...})
but to depends on its other and not happen asynch like down below i want something
$http({
method:"POST",
url:"....",
data:{'....})First_then().then(function(response){...})
UPDATE
i figured out tommorow i will post solution for everyone that has same issue in the future it was actually simple !
Solution
The Problem needed two requests that was depended on each other first as second's input. It has to be done in order so the body can execute properly after returning the properly json files
The Solution I had to use promises q.all first as parameter in Controller injection area like
bookingUpdateView.controller('liveBookingController',['$scope',
'$http', '$q', function($scope, $http, $q){
.... code here of entire controller....
}]);
then inside controller i make 2 promises as a $scope function and RETURN OR simply i could put them raw in $q.all([]).then but this was very messy so
$scope.promise = function(i){
return $http({
method:"POST",
url:"model/fetch_data_booking_view_seats_available.php",
data:{'movie_name':$scope.movieTitle,
'theatre_n':$scope.list_TP_5[i].theatre_name_fk,
..... etc.....}
})
}
Next the Queue itself i had a body to execute inside another $scope function like
$scope.updateTimePlay = function (id){
//..... code here .......
$q.all([$scope.promise(i),
$scope.promise1(i)])
.then(function(responses){
//....body here......
//in order to get JSON properly had to do
$scope.SeatsSub = responses.map((resp) => resp.data);
//so i could call it like this
$scope.SeatsSub[1][0].seatsAvailable;
//or use output to see what going on
console.log($scope.SeatsSub)
})
//....code here .....
}
Answered By - Michail Markou
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.