$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 中检查?
最佳答案
通过正确使用 Promise,您可以链接多个 Promise:
$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
});
};
关于angularjs - 检查 http.get Angular 中执行是否成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33790035/