I've got loop function with promises:
for (var a in $scope.atrakcje) {
  if ($scope.atrakcje[a].x && $scope.atrakcje[a].y) {
    App.countDistance($scope.atrakcje[a].x, $scope.atrakcje[a].y).then(function(km) {
      $scope.atrakcje[a].distance = km;
    });
  }
}
The problem with this loop is that all km values are assigned to the last $scope.atrakcje element. It should assign the first promise to the first element, the second to the second and so on. How to do it?
 
    