Weiß jemand, wie Sie überprüfen können, dass eine Ressource in AngularJS nicht abgerufen werden konnte?AngularJS Failed Resource GET
Zum Beispiel:
//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
}
});
Irgendwelche Ideen?
Perfect. Das ist genau das, was ich brauche. Danke :) – matsko
Das Problem ist in der if-Anweisung. Muss ich schreiben if (reponse.status == 404), if (antwort.status == 500), if (antwort.status == 501), if .. if .. if? Ist das nicht eine Code-Duplizierung? – Adelin
@Adio Sie können eine switch-Anweisung verwenden. –