簡體   English   中英

AngularJS資源-如何從。$ save獲取響應

[英]Angularjs Resource - how to get the response from .$save

我正在保存一些數據,這些數據可以從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'。

此功能如何運行?

在此先感謝您。

Postulation塊外部聲明變量$scope.postulation_id ,然后在該塊內部分配變量。 請注意,如果在調用$scope.postulation_id時回調尚未完成,則可能仍未undefined 您可能需要適當地放置代碼以解決該問題,在某些情況下使用$timeout或其他回調。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM