Javascript Angularjs资源-如何从$save获取响应
我正在保存一些数据,从API中得到正确的响应。在那之后,我将尝试在.$save函数结束后使用这些信息。这是我的密码:Javascript Angularjs资源-如何从$save获取响应,javascript,angularjs,angular-resource,Javascript,Angularjs,Angular Resource,我正在保存一些数据,从API中得到正确的响应。在那之后,我将尝试在.$save函数结束后使用这些信息。这是我的密码: auxPostulation = new Postulation($scope.postulation); auxPostulation.$save(null, function(response){ //I get the response and the id value without t
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.position\u id=undefined”
这个函数是如何工作的
在advanced中感谢您。在
假设
块外声明变量$scope.position\u id
,然后在块内分配它。请注意,如果在调用$scope.position\u id
时回调尚未完成,则仍可能会得到未定义的。您可能需要正确地放置代码以解决该问题,在某些情况下使用$timeout
或另一个回调