在处理save()方法$ ngResource错误回调 [英] handle error callback on save() method $ngResource
问题描述
我需要处理更新操作的错误回调,对于这个我使用的方法保存()
是这样的:
I need to handle error callback of an update operation, for this i'm using method save()
like this:
$scope.save = function (params) {
MigParams.save(params);
};
Migparams
服务是这样的:
angular.module('monitor').
factory('MigParams', function ($resource) {
return $resource('/restful/migparams');
});
这code的伟大工程,但我需要如果数据库发生错误认识。我曾在谷歌搜索,但我没有找到这种特殊情况。有没有的得到这样的方式?
在此先感谢
This code works great but i need to know if an error occurs in database. I have searched in google but i didn't find this particular case. Is there a way of get this?. Thanks in advance
推荐答案
的https: //docs.angularjs.org/api/ngResource/service/$resource :
非GET下课的行动:Resource.action([参数],POSTDATA,[成功],[错误])
non-GET "class" actions: Resource.action([parameters], postData, [success], [error])
非GET下课的实例:Resource.action([参数],[成功],[错误])
non-GET "class" instance: Resource.action([parameters], [success], [error])
$资源
的保存方法分为非GET类的实例类),所以它的错误回调是第三个参数。
$resource
's save method falls into the non-GET 'class' instance category), so its error callback is the third argument.
您code看起来像:
$scope.save = function (params) {
MigParams.save(params,
function(resp, headers){
//success callback
console.log(resp);
},
function(err){
// error callback
console.log(err);
});
};
这篇关于在处理save()方法$ ngResource错误回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!