有誰知道如何檢查資源是否無法在AngularJS中獲取?AngularJS失敗的資源GET
例如:
//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
}
});
任何想法?
完善。這正是我需要的。謝謝:) – matsko 2012-07-23 17:37:56
問題出在if語句中。我需要寫if(reponse.status == 404),if(reponse.status == 500),if(reponse.status == 501),if .. if .. if?這不是代碼複製 – Adelin 2012-12-04 09:14:27
@Adio您可以使用switch語句。 – 2013-02-09 01:50:01