Angularjs类似于jQuery.always()
我想向我的服务器发出HTTP请求,但找不到关于如何以jQuery样式生成Angularjs类似于jQuery.always(),angularjs,Angularjs,我想向我的服务器发出HTTP请求,但找不到关于如何以jQuery样式生成.always()的问题的答案 根据Angular的$http文档,只有以下结构: // Simple GET request example : $http.get('/someUrl'). then(function(response) { // this callback will be called asynchronously // when the response is available
.always()
的问题的答案
根据Angular的$http
文档,只有以下结构:
// Simple GET request example :
$http.get('/someUrl').
then(function(response) {
// this callback will be called asynchronously
// when the response is available
}, function(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
这里有一个finally()
:
无论结果如何,它都会被调用
您可以在
$q
$http.get(…).finally(function(){…})的文档中了解这一点代码>但是为什么Angular的网站上没有信息?
$http.get('/someUrl').
then(function(response) {
// this callback will be called asynchronously
// when the response is available
}.catch(error) {
// called asynchronously if an error occurs
// or server returns response with an error status.
}).finally() {
//Always do something
});