相关疑难解决方法(0)

将参数传递给angularjs中的promise的回调

我想弄清楚是否有任何方法可以将索引参数传递给promise的回调函数.例如.

serviceCall.$promise.then(function(object){
    $scope.object = object;
});
Run Code Online (Sandbox Code Playgroud)

现在我想传入一个数组索引参数as

serviceCall.$promise.then(function(object,i){
    $scope.object[i] = something;
});
Run Code Online (Sandbox Code Playgroud)

可以这样做吗?请告诉我.

这是下面的代码

StudyService.studies.get({id:    
$routeParams.studyIdentifier}).$promise.then(function(study) {
$scope.study = study;
for(var i=0;i<study.cases.length;i++){
  StudyService.executionsteps.get({id:   
  $routeParams.studyIdentifier,caseId:study.cases[i].id})
      .$promise.then(function(executionSteps,i){
      $scope.study.cases[i].executionSteps = executionSteps;
      });
  }
});
Run Code Online (Sandbox Code Playgroud)

javascript callback promise angularjs

16
推荐指数
1
解决办法
2万
查看次数

标签 统计

angularjs ×1

callback ×1

javascript ×1

promise ×1