title: Cannot get iteration count of for loop cycle inside of the service result -> then
body: <p>i have following method:</p>
  
  <pre><code>var i;
  $scope.playAllSelectedSounds = function() {
              try {
  
                  for( i; i &lt; $scope.selectedSounds.length; i++) {
                      var fileName = $scope.selectedSounds[i].file;
                      var volume = $scope.selectedSounds[i].defaultVolume;
                      var filePath  = "sounds/" +fileName+".mp3";
                      console.log(fileName);
                      MediaSrv.loadMedia(filePath).then(function(media){
                          console.log(media);
                          // !!!!!!!!!!!  HERE I CANNOT GET value of the i VARIABLE
                          $scope.selectedSounds[i].state = 1;
                          // !!!!!!!!!!!  HERE I CANNOT GET value of the i VARIABLE
                          $scope.selectedSounds[i].mediaInstance = media;
                          media.play();
                          media.setVolume(volume);
                      });
  
                  }
              } catch(e) {
                  alert(JSON.stringify(e));
                  console.log(e);
                  $scope.showAlert("Error", "Error during the playing item");
              }
          };
  </code></pre>
  
  <p>Problem is that inside of the service:</p>
  
  <pre><code>                MediaSrv.loadMedia(filePath).then(function(media){
  </code></pre>
  
  <p>I cannot get number o for cycle loop which i need to set in:</p>
  
  <pre><code>                $scope.selectedSounds[i].state = 1;
  </code></pre>
  
  <p>Variable <strong>i</strong> is global i still cannot reach them. How can i solve it please?</p>