Reputation: 1101
$scope.func1 = function() {
$http.get(url, {params}).success(function(result){
// code
}).error(function(error){
// error
})
}
$scope.func2 = function() {
$scope.func1();
// when http of func1 done executing, call following code
}
How do I check in func2 if http.get
success of func1 is done executing?
Upvotes: 2
Views: 3063
Reputation: 193261
By using promises properly you can chain multiple promises:
$scope.func1 = function () {
return $http.get(url, {/*params*/})
.then(function (response) { // success is deprecated, use then instead
// code
return something;
})
.catch(function (error) { // use catch instead of error
// error
});
};
$scope.func2 = function () {
$scope.func1().then(function(something) {
//when http of func1 done executing, call following code
});
};
Upvotes: 5