为什么不推荐使用AngularJS

为什么不推荐使用AngularJS

本文介绍了为什么不推荐使用AngularJS $ http成功/错误方法?从v1.6中删除了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AngularJS文档已针对 $ http 成功错误方法。

The AngularJS documentation has a Deprecation Notice for the $http success and error methods. Is there a specific reason this abstraction was removed from the library?

推荐答案

问题是 .success是否有特定原因? .error 方法不可链接,因为它们忽略返回值。这给熟悉 chaining 的人带来了问题,并鼓励了不熟悉 chaining 的人提供的劣质代码。见证所有使用的示例。

The problem was that .success and .error methods are not chainable because they ignore return values. This caused problems for people familiar with chaining and encouraged poor code from people unfamiliar with chaining. Witness all the examples on StackOverflow that use the deferred anti-pattern.

要引用AngularJS团队之一:

To quote one of the AngularJS team:

— AngularJS Issue #10508 $http .success/.error dissimilar from how .then works.












UPDATE



已弃用的。成功 .error 方法已从AngularJS 1.6中删除。


UPDATE

The deprecated .success and .error methods have been removed from AngularJS 1.6.

$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;
    ...
  });

这篇关于为什么不推荐使用AngularJS $ http成功/错误方法?从v1.6中删除了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 15:06