$http
したがって、結果に対して成功またはエラーを呼び出すと、$http
プロミスで呼び出され、更新されたものではなく元のものが返されることを知っています。私が本当に理解していないのは、なぜですか?
現在、次のように記述できます。
$http(config)
.success(function(data) { console.log(data); return 1; })
.then(function (response) {
var msg = 'Hey, I am the original response, not 1, ';
msg += 'and I can run even before success is completed. ';
msg += 'This is nearly fake chaining...';
console.log(msg);
});
より多くのコーディングスタイル、ここのコードをこれに置き換えない正当な理由はありますか?
// The util method has been put after the return
// just as the other $http internal methods
return decoratePromise(promise);
// Util method to add method 'success' and 'error'
// to a promise. This will spread the raw respons
function decoratePromise(p) {
p.success = function(fn) {
return decoratePromise(p.then(function(response) {
return fn(response.data, response.status, response.headers, config);
}));
};
p.error = function(fn) {
return decoratePromise(p.then(null, function(response) {
return fn(response.data, response.status, response.headers, config);
}));
};
return p;
}
これらの 2 つの方法についてどう考えればよいかよくわかりません。この制限に関して、それらを使用する正当な理由はありますか?
情報をありがとう!