0
我有一個angularjs項目。我只是想知道,如果找不到請求的視圖/部分(HTTP 404),如何向用戶顯示消息。目前,角度啓動請求並獲得404響應,包括error-html,但用戶沒有看到網站的任何更改。 /:Angularjs部分未找到
我有一個angularjs項目。我只是想知道,如果找不到請求的視圖/部分(HTTP 404),如何向用戶顯示消息。目前,角度啓動請求並獲得404響應,包括error-html,但用戶沒有看到網站的任何更改。 /:Angularjs部分未找到
爲 'responseError'
angular.module("app").config(function($provide, $httpProvider) {
// register the interceptor as a service
$provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
return {
'responseError': function(response) {
if (response.status == 404) {
// user hit a 404 -- you can check response.url to see if it matches
// your template directory and act accordingly
return responseOrNewPromise
}
return $q.reject(rejection);
}
};
});
$httpProvider.interceptors.push('myHttpInterceptor');
});
響應攔截器已被棄用添加$ HTTP攔截器(上this page向下滾動)。而我正在使用$ ressource而不是$ http。 – bernhardh
@leftjustified介紹'$ httpProvider.responseInterceptors'和'$ httpProvider.interceptors'之間的區別。 '$ resource'使用'$ http',在你的問題中你討論視圖。我看不到'$ resource'的連接。 – zeroflagL
哦。好的,對不起,我的錯。我在這個主題上發現了一篇很棒的博文:http://blog.brunoscopelliti.com/http-response-interceptors – bernhardh