AngularJS服务上的保存不调用错误回调()方法 [英] AngularJS service not invoking error callback on save() method

查看:109
本文介绍了AngularJS服务上的保存不调用错误回调()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用angularjs RESTful服务$资源,我调用$保存功能。但是,错误回调我传递给它不会被调用。服务器发送一个418错误,我想因为它不是200将导致被调用错误回调。但是,它从来不会。我无法找到任何文件说明什么HTTP错误codeS将导致错误回调被调用。

So I'm using angularjs restful service $resource and I'm calling $save function. However, the error callback I pass to it is not being called. The server is sending a 418 error which I thought since it's NOT 200 would result in the error callback being invoked. But, it never does. I can't find any documentation stating what http error codes will result in the error callback being called.

下面是我的code:

var modalScope = $scope.$new();
modalScope.showPassword = false;
modalScope.message = null;
modalScope.user = new User();

modalScope.submit = function(user) {
    user.$save( {}, function(data,headers) {
        // do the success case
    }, function(data,headers) {
        // do the error case                
    });
};

该modalScope.user被传递给定义提交函数。那么,为什么这个错误回调不会被调用的问题?

The modalScope.user is being passed to the submit function defined. So what's the problem why this error callback isn't being called?

推荐答案

我发现在ngResource源$ C ​​$ C以下

I found the following in the ngResource source code

$http({method: 'GET', url: '/someUrl'}).
    success(function(data, status, headers, config) {
        // this callback will be called asynchronously
        // when the response is available
    }).
    error(function(data, status, headers, config) {
        // called asynchronously if an error occurs
        // or server returns response with status
        // code outside of the <200, 400) range
    });

我有点困惑的范围标识,但似乎它实际上应该调用错误的方法。也许你发现了一个bug。

I am kind of confused about the range notation but it seems it should actually call the error method. Maybe you found a bug.

这篇关于AngularJS服务上的保存不调用错误回调()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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