Passing parameters to promise's callback in angularjs
you can use a closure for that.
for example, in your code, use something like:
function callbackCreator(i) { return function(executionSteps) { $scope.study.cases[i].executionSteps = executionSteps; }}StudyService.studies.get({id: $routeParams.studyIdentifier}) .$promise.then(function(study) { $scope.study = study; for(var i=0;i<study.cases.length;i++) { var callback = callbackCreator(i); StudyService.executionsteps.get({id: $routeParams.studyIdentifier,caseId:study.cases[i].id}) .$promise.then(callback); }});
I've done something similar and I put a promise on each and then used $q.all()
on the array of promises like:
$q.all( arrayOfPromises ).then(function(results) { console.log(results[0], results[1], results[2]);});