加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 角$http / jquery完全等效

发布时间:2020-12-17 07:43:38 所属栏目:安全 来源:网络整理
导读:有没有办法用角度$http模块来模拟 jquery‘完整’回调?我有一些代码,无论请求成功还是失败,我想执行,现在我发现自己不得不写这个: $http.get(someUrl).success(function(){ successCode(); completeCode(); }).error(function(){ errorCode(); completeCod
有没有办法用角度$http模块来模拟 jquery‘完整’回调?我有一些代码,无论请求成功还是失败,我想执行,现在我发现自己不得不写这个:
$http.get(someUrl).success(function(){
        successCode();
        completeCode();
    }).error(function(){
        errorCode();
        completeCode();
    })

但我宁愿写一些类似的东西:

$http.get(someUrl).success(function(){
        successCode();
    }).error(function(){
        errorCode();
    }).complete(function(){
        completeCode();
    })

我也尝试过使用promise API,但我最终也有同样的问题.任何建议?

更新2014年8月:.always已更名,最终版本为Angular.喜欢.

请注意,为了支持IE8,您必须使用括号符号作为[“finally”].

您可以在AngularJS中使用.always

这个更改是相当新的(您可以在jQuery中执行一段时间),您可以看到提交here.这需要您具有AngularJS 1.1.5或更高版本.

always(callback) – allows you to observe either the fulfillment or rejection of a promise,
but to do so without modifying the final value. This is useful to release resources or do some
clean-up that needs to be done whether the promise was rejected or resolved. See the 07001 for
more information.

Fiddle

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读