javascript - AngularJs : $http chaining -
i have these 2 functions , sample of code
var getrangetime = function(numserie){ $http.get("data/tempsgammes.json").then(function(res){ return $scope.time = res.data[numserie].temps })} var updatescreen = function() { $http.get("http://localhost:5000").then(function(response){ $scope.numserie = response.data.refdetail.num_serie $scope.numteam = response.data.team $scope.t = getrangetime($scope.numserie) //rest of code code }
here want :
first of all, call function updatescreen() serial number (numserie), depending on value of numserie, function getrangetime() exectued time, , function updatescreen() continue execution using result of getrangetime().
the problem here asynchronous, mean updatesreen() should wait getrangetime() until returns desired value, it's kind of async , await.
i've tried didn't work , don't know how use them much, searched here , tried existing solutions didn't go too, got undefined.
can me ?
a little late here can use callbacks(i haven't tested should work):
var updatescreen = function(callback) { $http.get("http://localhost:5000").then(function(response){ $scope.numserie = response.data.refdetail.num_serie $scope.numteam = response.data.team $scope.t = getrangetime($scope.numserie) callback($scope.numserie); } } updatescreen(function(numserie) { $http.get("data/tempsgammes.json").then(function(res){ return $scope.time = res.data[numserie].temps } })
Comments
Post a Comment