【发布时间】:2016-07-28 05:18:34
【问题描述】:
我想问一下这个方法的区别 我关心的是 .then 和 .success、function 和 .error 之间的区别 谢谢。
// Simple GET request example:
$http({
method: 'GET',
url: '/someUrl'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
和
// Simple GET request example:
$http({
method: 'GET',
url: '/someUrl'
}).success(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}).error( function(data) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
【问题讨论】:
-
不要使用success和error,使用then和catch。
-
.success和.error已弃用。 -
在这里找到 promise 的文档:stackoverflow.com/documentation/javascript/231/…
标签: javascript angularjs api angular-promise angular-http