![](/img/trans.png)
[英]how to get json response from restapi in angularjs using $resource?
[英]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.