javascript – AngularJS服务不会在save()方法上调用错误回调

前端之家收集整理的这篇文章主要介绍了javascript – AngularJS服务不会在save()方法上调用错误回调前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我使用 angularjs restful服务$资源,我正在调用$save函数.然而,我传递给它的错误回调没有被调用.服务器正在发送一个418错误,我认为,因为它不是200将导致错误回调被调用.但是,它从来没有.我找不到任何文档,说明什么是http错误代码会导致调用错误回调.

这是我的代码

  1. var modalScope = $scope.$new();
  2. modalScope.showPassword = false;
  3. modalScope.message = null;
  4. modalScope.user = new User();
  5.  
  6. modalScope.submit = function(user) {
  7. user.$save( {},function(data,headers) {
  8. // do the success case
  9. },headers) {
  10. // do the error case
  11. });
  12. };

modalScope.user正被传递给定义的submit函数.那么这个错误回调没有被调用的问题是什么?

解决方法

我在ngResource源代码中找到了以下内容
  1. $http({method: 'GET',url: '/someUrl'}).
  2. success(function(data,status,headers,config) {
  3. // this callback will be called asynchronously
  4. // when the response is available
  5. }).
  6. error(function(data,config) {
  7. // called asynchronously if an error occurs
  8. // or server returns response with status
  9. // code outside of the <200,400) range
  10. });

我对范围符号感到困惑,但它似乎应该实际调用错误方法.也许你发现了一个错误.

猜你在找的JavaScript相关文章