I am feeling a bit perplexed about how and when to use the .then
and/or .success
functions.
Here is a function example:
$scope.handleData = function(option){
if(option == 1){
link = firstLink/;
}else{
link = secondLink/;
}
var dataInfo = {some: information};
$http.post(link, dataInfo).then(function(response){
$http.get('profileLink/'+response.data.contactId[0])
.then(function(contactResponse){
//assign contactResponse to appropriate $scope variables
});
});
if(option == 1){
option = 2;
$scope.handleData(2);
}
}
The above function is called using $scope.handleData(1)
. The firstLink
quickly retrieves 50 results while the secondLink
loads 100K results which takes more time. Strangely, the profileLink
does not show any results until I receive feedback from the secondLink
.
Could you provide some guidance on how I can ensure that the profileLink
returns results without getting stuck waiting for the response from secondLink
?