AngularJS文档中对
$http
的success
和error
方法发布了弃用通知。这个方法被从库中移除的原因是什么?$http
的success
和error
方法发布了弃用通知。这个方法被从库中移除的原因是什么?.success
和.error
方法不能链式调用,因为它们忽略返回值。这对于熟悉链式调用的人造成了问题,并鼓励不熟悉链式调用的人编写低质量的代码。请看StackOverflow上使用deferred anti-pattern的所有示例。弃用通知 (v1.5)
$http
的旧版 promise 方法success
和error
已被弃用。请改用标准的then
方法。如果将$httpProvider.useLegacyPromiseExtensions
设置为false
,则这些方法将抛出$http/legacy
错误。
AngularJS 1.6已经移除了不建议使用的.success
和.error
方法。
Due to b54a39,
$http
's deprecated custom callback methods -.success()
and.error()
- have been removed. You can use the standard.then()
/.catch()
promise methods instead, but note that the method signatures and return values are different.
$http(...) .then(function onSuccess(response) { // Handle success var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... }).catch(function onError(response) { // Handle error var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... });
.then(successCallback, errorCallback)
,因此他们可能旨在使用js模式。