1

Lets say I have a angular view which gets populated from the service:

$http.get("" + window.ENDPOINT + "/main_things/" + $scope.mainThingId + ".json").success(function(data) {
  return $scope.main_thing = data;
});

Let's say I want to load another bit of information to my page, but the other bit is utilizing some slow external services, so I want to load it asynchronously:

$http.get("" + window.ENDPOINT + "/secondary_things/" + $scope.parentMainThingId + ".json").success(function(data) {
  return $scope.secondary_thing = data;
});

How can I structure my code in the angular controller so I can load the main_thing first and then load the secondary thing?

Any help would be appreciated.

1 Answer 1

3

By running second request in first request's success callback:

$http.get("" + window.ENDPOINT + "/main_things/" + $scope.mainThingId + ".json")
  .success(function(data) {
    $scope.main_thing = data;
    $http.get("" + window.ENDPOINT + "/secondary_things/" + $scope.parentMainThingId + ".json")
      .success(function(data) {
        $scope.secondary_thing = data;
    });
  });
Sign up to request clarification or add additional context in comments.

Comments

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.