我可以code A"最后"与AngularJS资源版本1.2.3?版本、资源、QUOT、code

2023-09-13 03:15:36 作者:我是纯情小骚货

我在使用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 。您应该能够设置最后那里。

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

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

看文档

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

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.

 
精彩推荐
图片推荐