0

I don't think I understand how http and javascript work because I have this method,

$scope.myfunc= function (arg) {
  var flag = false;
  $http.get('/someurl/' + arg).
    success(function (data) {
      if(check(data))
        flag = true;
        console.log("i want this first");
    })
  }
  console.log("i want this second");
  return flag;
};

and the order in which things are done are not how I want them.

"i want this second" app.js:109
GET {some console stuff}
"i want this first"

I'm calling this thru another method where I check the json and do something based on what the data looks like, ie the flag. How can I have the http stuff do its thing before returning my flag variable.

  • You'd need to run the `GET` synchronously. It looks like that [isn't yet possible with angular](https://github.com/angular/angular.js/issues/2391). – dirn Jun 07 '14 at 17:46
  • possible duplicate of [Can you wait for javascript callback?](http://stackoverflow.com/questions/436608/can-you-wait-for-javascript-callback) – Sean Vieira Jun 08 '14 at 02:31

0 Answers0