Skip to content

Instantly share code, notes, and snippets.

@pyadav
Forked from guptasanchit90/AngularNetworkUtils.js
Created August 8, 2016 03:37
Show Gist options
  • Select an option

  • Save pyadav/f3dd711f71d2ab31e50cf0995c651757 to your computer and use it in GitHub Desktop.

Select an option

Save pyadav/f3dd711f71d2ab31e50cf0995c651757 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