Created
July 5, 2013 06:04
-
-
Save frozonfreak/5932275 to your computer and use it in GitHub Desktop.
Check if user is online
AngularJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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