Angularjs 两次捕捉成功响应
控制台输出似乎总是:Angularjs 两次捕捉成功响应,angularjs,Angularjs,控制台输出似乎总是: This is the first response This is the second response 因为将首先调用内部方法的success函数。这是正确的假设吗?订单有保证吗 app.controller("ctrl", function($scope,$http) { var getUrl = function () { var config = { method: 'GET',
This is the first response
This is the second response
因为将首先调用内部方法的success函数。这是正确的假设吗?订单有保证吗
app.controller("ctrl", function($scope,$http) {
var getUrl = function () {
var config = {
method: 'GET',
url: 'some.txt'
};
return $http(config)
.success(function (response, status, headers, config) {
console.log('This is the first response');
})
.error(function (data, status, headers, config) {
});
};
var init = function () {
var promise = getUrl();
promise.then(
function() {
console.log('This is the second response');
});
};
init();
});
是的,因为$http本身返回一个承诺,您在上面所做的就是承诺链接
尽管使用$http.then(success,error).then(success,error)可能更好 是的,你的假设是正确的。该函数被称为
then()
,理由很充分;)。