Reputation: 20168
I have an issue with a variable which is not being updated in the callback function of a promise as in the block of code below:
$scope.showSelected= function (node){
var promise = $http.get("http://127.0.0.1:5000/getResource?ldpr="+node.iri);
promise.then(function(result){
node = result.data;
});
};
$scope.showSelected
is a callback used by a widget. It has a parameter node
which I am trying to update within the callback of the promise. How can I update this variable within callback of the promise
Upvotes: 0
Views: 515
Reputation: 1
No value is return
ed from $scope.showSelected
function. return
a value from the asynchronous function call, use .then()
to perform a task when the asynchronous call which returns a Promise
completes
$scope.showSelected = function (node){
return $http.get("http://127.0.0.1:5000/getResource?ldpr="+node.iri);
};
$scope.showSelected(node)
.then(function(result) {
// do stuff with `result` : `node`
})
.catch(function(err) { // handle error
console.log(err)
})
Upvotes: 1