Skip to content

Instantly share code, notes, and snippets.

@frozonfreak
Created July 5, 2013 06:04
Show Gist options
  • Save frozonfreak/5932275 to your computer and use it in GitHub Desktop.
Save frozonfreak/5932275 to your computer and use it in GitHub Desktop.
Check if user is online AngularJS
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
app.run(function($window, $rootScope) {
$rootScope.online = navigator.onLine;
$window.addEventListener("offline", function () {
$rootScope.$apply(function() {
$rootScope.online = false;
});
}, false);
$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