javascript - How to make angular wait for a function to return a value before proceeding -


i have function this:

$scope.process = function(){      $http().success(){          return something;         } }; 

just assume code complete.. , when call it

alert($scope.process()); 

it displays undefined.

how angular wait return of function before proceeding?

you don't. instead, tell when response available:

$scope.process = function() {     $http.get(path).success(function(data) {         alert("i received " + data);     }); }; 

or, if want configurable:

$scope.process = function(callback) {     $http.get(path).success(callback); }; 

Comments