Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
134 views
in Technique[技术] by (71.8m points)

javascript - AngularJS Failed Resource GET

Does anyone know how you can check to see that a resource failed to be fetched in AngularJS?

For example:

//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
    }
});

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

An additional callback function after your first callback function should fire when there is an error. Taken from the docs and group 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])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...