2017-01-23 80 views
0

我保存了一些数据,我从API中获得了正确的响应。之后,我试图在我的。$ save函数结束后使用这些信息。这里是我的代码:

auxPostulation = new Postulation($scope.postulation); 
         auxPostulation.$save(null, function(response){ 
        //I get the response and the id value without trouble. 
          $scope.postulation_id = response.id; 
         },function(error){ 
          console.log('erro'); 
         }); 

我想使用的呼叫之外的反应,但我不能达到它。总是得到'$ scope.postulation_id = undefined'。

这个函数的行为如何?

谢谢您的高级。

回答

0

Postulation块之外声明变量$scope.postulation_id,然后在块内部分配它。请注意,如果呼叫$scope.postulation_id时回拨未完成,您仍可能获得undefined。您可能需要妥善处理代码,以便在某些情况下使用$timeout或其他回调来解决该问题。