2017-01-23 78 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或其他回調來解決該問題。