In my JavaScript code, I am working with a list called $scope.propname that contains an object named latlong. My goal is to calculate the distance of all properties from a specific location. This is the approach I have taken:
for (var i = 0; i < $scope.propname.length; i++) {
if ($scope.propname[i].latlong == "") {
var pptlatlong = ("" + "," + "");
} else {
var pptlatlong = $scope.propname[i].latlong.replace(/\s*,\s*/g, ",");
}
var latlongdata = {
scoord: $scope.loclatlong,
ecoord: pptlatlong
}
$http({
method: 'post',
data: latlongdata,
url: $rootScope.ServiceBaseUri + 'Map/geolocation'
}).then(function successCallback(resp) {
$scope.latlongdist = resp.data;
}, function errorCallback(resp) {});
$scope.propname[i].dist = $scope.latlongdist;
}
After running this loop, I noticed that all objects named dist in the list have the same value. I believe this is because the loop continues before each HTTP response has finished. Is there a way to pause the loop until each HTTP request completes before proceeding?