0
我如何修改攔截器內的$scope
變量?
var portal = angular.module('portal', ['ngResource', 'ui.utils', 'ngRoute']).config(function($httpProvider) {
$httpProvider.interceptors.push(function($q) {
return {
responseError: function(rejection) {
if(rejection.status == -1) {
// i want to modify this variable to true/false
$scope.restApiServerOnline = false;
return;
}
return $q.reject(rejection);
}
};
});
});
上述代碼的目的是攔截所有HTTP交/ GET到REST服務器製成,並且如果失敗,切換此範圍可變。
我不認爲它可能在攔截器中注入當前範圍,爲什麼你需要更新範圍? – Sherlock