-
-
Save TiagoWinehouse/207713c81a977919c9b9ef440201535f to your computer and use it in GitHub Desktop.
Online x Offline
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
app.run(function($rootScope) { | |
// console.log("online:" + navigator.onLine); | |
$rootScope.online = navigator.onLine ? 'online' : 'offline'; | |
$rootScope.$apply(); | |
if (window.addEventListener) { | |
window.addEventListener("online", function() { | |
$rootScope.online = "online"; | |
$rootScope.$apply(); | |
}, true); | |
window.addEventListener("offline", function() { | |
$rootScope.online = "offline"; | |
$rootScope.$apply(); | |
}, true); | |
} else { | |
document.body.ononline = function() { | |
$rootScope.online = "online"; | |
$rootScope.$apply(); | |
}; | |
document.body.onoffline = function() { | |
$rootScope.online = "offline"; | |
$rootScope.$apply(); | |
}; | |
} | |
}); | |
/////////////////////////////////////////////////// | |
var app = module('yourApp', []); | |
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