I'm saving some data which I get a response from my API correctly. After that, I'm trying to use that information once my .$save function ends. Here's my code:
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');
});
I wanna use that response outside that call but I cannot reach it. Always getting '$scope.postulation_id = undefined'.
How this function behave?
Thank you in advanced.
Declare the variable $scope.postulation_id
outside the Postulation
block and then assign it inside the block. Note that you might still get undefined
in case the callback has not completed when you call for $scope.postulation_id
. You might need to lay your code properly to take care of that issue, using $timeout
or another callback in some cases.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.