有谁知道如何在 AngularJS 中检查资源是否无法获取?
例如:
//this is valid syntax
$scope.word = Word.get({ id : $routeParams.id },function() {
//this is valid, but won't be fired if the HTTP response is 404 or any other http-error code
});
//this is something along the lines of what I want to have
//(NOTE THAT THIS IS INVALID AND DOESN'T EXIST)
$scope.word = Word.get({ id : $routeParams.id },{
success : function() {
//good
},
failure : function() {
//404 or bad
}
});
有什么想法吗?
最佳答案
当出现错误时,应在您的第一个回调函数之后触发一个额外的回调函数。取自 docs和组post :
$scope.word = Word.get({ id : $routeParams.id }, function() {
//good code
}, function(response) {
//404 or bad
if(response.status === 404) {
}
});
- HTTP GET "class" actions: Resource.action([parameters], [success], [error])
- non-GET "class" actions: Resource.action([parameters], postData, [success], [error])
- non-GET instance actions: instance.$action([parameters], [success], [error])
关于javascript - AngularJS 资源获取失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11598097/