How to make angular wait for a function to return a value before proceeding
angularjs, javascript
Solution
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);
};
Problem
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?