1
$scope.fetchQA = function() {

    $scope.url = 'js/jsons/QA.json';

    $http({method: 'GET', url: $scope.url}).
      success(function(data, status, headers, config) {
        $scope.QA = data;
    });
  }

  $scope.fetchQA();

  function x(){
    alert(QA);
  }

How do i use function x as a callback for $http.get? or is there any other way to ensure that x() will get executed only after reception of data in fetchQA?

1 Answer 1

2

Put it in the callback right after your logic:

$http({method: 'GET', url: $scope.url}).
  success(function(data, status, headers, config) {
    $scope.QA = data;
    x();
});
Sign up to request clarification or add additional context in comments.

2 Comments

when u put it like that! I wonder why didn't i think of it! :)
@SangramSingh -- Happens all the time, especially when you start thinking async in the beginning. :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.