Passing Parameters To Promise's Callback In Angularjs
I am trying to figure out is there is any way to pass in an index argument to a promise's callback function. For instance. serviceCall.$promise.then(function(object){ $scope.ob
Solution 1:
you can use a closure for that.
for example, in your code, use something like:
functioncallbackCreator(i) {
returnfunction(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);
}
});
Post a Comment for "Passing Parameters To Promise's Callback In Angularjs"