Hello guyz I am using this code in .run function and its working but when I place the same code in controllers
it says window.connection does not exists why???
//Network Code
if (window.Connection) {
alert(" Connection Detected Yahooooo!!! :)");
}
}
else {
alert(‘Cannot find Window.Connection’);
}
Add following code to .run function
$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);
Then Add a watcher to observe change in rootscope in your controller
$scope.$watch(‘online’, function(Status) { …
console.log(Status)
});
1 Like
thank you in .run it work just fine