我可以code A"最后"与AngularJS资源版本1.2.3? [英] Can I code a "finally" with AngularJS resource version 1.2.3?

查看:170
本文介绍了我可以code A"最后"与AngularJS资源版本1.2.3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用AngularJS资源的以下code:

I have the following code using AngularJS resource:

var entityResource = $resource('/api/:et/', {
                            et: $scope.entityType
                     });
entityResource.save(data,
   function (result) {
      // code
      $scope.modal.submitDisabled = false;
   }, function (result) {
      // code
      $scope.modal.submitDisabled = false;
   });

有什么样一个终于,我可以用这样我就可以把code可以禁用(和我的其他code)的成功和错误之外吗?也可我现在用.success和.error或者我还是要code两个函数中()?

Is there something like a finally that I can use so I can put the code to disable (and my other code) outside of the success and error? Also can I now use .success and .error or do I still have to code as two functions inside () ?

我做1.2.3通知的变化,但我不知道我是否了解这些应用。

I did notice changes in 1.2.3 but I am not sure if I understand how these apply.

推荐答案

有应该在你的 entityResource $承诺属性$ C>。您应该能够设置最后那里。

There Should be a $promise property on your entityResource. You should be able to set finally there.

entityResource.$promise['finally'](function(){
  // finally do something
});

看<一个href=\"http://docs.angularjs.org/api/ngResource.%24resource#The%20Resource%20instances%20and%20collection%20have%20these%20additional%20properties%3a\"相对=nofollow>文档

更新::您可以做这样的事情:

update: You could do something like this:

//Using the promise on your resource.
function success(){/**success*/};
function error(){/**failure*/};
function last(){/**finally*/};
entityResource.save(data,success,error).$promise.finally(last);

通过使用角的 $ Q 。然后您将调用 $消化周期。这将更新您的看法,通常是太棒了。

By using angular's $q and .then You will invoke a $digest cycle. Which will update your view, which is usually fantastic.

这篇关于我可以code A&QUOT;最后&QUOT;与AngularJS资源版本1.2.3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆