$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
}
如果func1的http.get
成功执行,如何检查func2?
答案 0 :(得分:5)
通过正确使用承诺,您可以链接多个承诺:
$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
});
};