输入一些值,当用户断开网络,并尝试执行任何动作后。我的应用程序没有显示任何错误消息,指出“没有互联网连接”在控制台它扔
angular_1.3.13.js:11613类型错误:在Object.handleError无法读取空的特性 '错误'(apiHelper.js:120)在shortnoteCreateController.js:88 angular_1.3.13.js:9382在processQueue(angular_1.3.13.js在范围14407)$摘要(angular_1.3.13.js:::13195)在angular_1.3.13.js:13211的范围$的eval(angular_1.3.13.js。14223)的范围$申请(angular_1.3.13.js :14512)在完成(angular_1.3.13.js:9665)在completeRequest(angular_1.3.13.js:9855)
在下面的代码来处理错误。
this.handleError =函数(状态,数据){
if (status == URLs.unauthorizedCode && address.location.hash != "#/login") {
var userdet = this.getUserDetailsFromServer(URLs.HTTP_GET, URLs.requestheaders);
userdet.success(function(data) {
//navigate to login page when unauthorized operations performed
//its a rare case of getting permission reverted by PA when in action
//or if logged out in another tab or logged in as another user in another tab
//localStorageService.set('successmsg', 'You have been prevented from an unauthorized access');
displayResult.showErrorResults(Constants.authorizationFailureMsg,'success');
address.location.href = URLs.loginView;
//address.location.reload();
//console.info("in handle error auth fail");
});
userdet.error(function(data) {
localStorageService.set('successmsg', 'You have been prevented from an unauthorized access');
localStorageService.clearAll();
address.location.href = URLs.loginView;
address.location.reload();
displayResult.showErrorResults(Constants.authorizationFailureMsg,'success');
//console.info("in handle error auth fail");
});
} else if(status == URLs.notFoundCode){
address.location.href = URLs.notFoundPage;
}else {
$rootScope.rs_error_status = status;
//console.log("inside apihelper", data);
if (data.error) {
$rootScope.rs_error_data = data;
//console.info("in error");
} else if (data.errors) {
//console.info("in errors");
$rootScope.rs_error_data = data.errors;
}
var modalInstance = $modal.open({
templateUrl : 'userinterface/pages/modal/errordialog.html',
controller : 'modalController'
});
modalInstance.result.then(function() {
//console.info("Exiting modal popup");
}, function() {
});
}
您可以使用navigator.onLine返回布尔值true / false为在线和离线
您也可以online/offline
事件附加到窗口
window.addEventListener('offline', (e)=> { //code here});
window.addEventListener('online', (e) => { //some code here});