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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -