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.
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;
});
});