Skip to content

Instantly share code, notes, and snippets.

@guptasanchit90
Created July 31, 2016 14:50
Show Gist options
  • Save guptasanchit90/9e607fe97caef04355d1105c6a8b0867 to your computer and use it in GitHub Desktop.
Save guptasanchit90/9e607fe97caef04355d1105c6a8b0867 to your computer and use it in GitHub Desktop.
app.run(function($window, $rootScope) {
$rootScope.online = navigator.onLine;
/**
Generate event offline when user disconnects from Internet
$scope.$watch('offline', function(newStatus) { ... });
**/
$window.addEventListener("offline", function() {
$rootScope.$apply(function() {
$rootScope.online = false;
});
}, false);
/**
Generate event online when user connects from Internet
$scope.$watch('online', function(newStatus) { ... });
**/
$window.addEventListener("online", function() {
$rootScope.$apply(function() {
$rootScope.online = true;
});
}, false);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment