I have function like this:
$scope.process = function(){
$http().success(){
return something;
}
};
Just assume that the code is complete.. and then when I call it
alert($scope.process());
it displays undefined.
How do I get the angular to wait for the return of the function before proceeding?
You don't. Instead, you tell it what to do when the response is available:
$scope.process = function() {
$http.get(path).success(function(data) {
alert("I just received " + data);
});
};
Or, if you want this to be configurable:
$scope.process = function(callback) {
$http.get(path).success(callback);
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With