Reputation: 1618
Hello i am using angularjs to create an phonegap app. Here is my controller:
module.controller('MainController', function($scope, $window, $rootScope){
$scope.funda="new Funda";
$scope.deviceReady = false;
document.addEventListener("deviceready", onDeviceReady, false);
console.log('mainCtrl is loaded');
function onOnline(){
alert('device is in online mode'); //cannot reach here
$rootScope.online = true;
$scope.online = $rootScope.online;
}
function onOffline(){
alert('device is not ready');
$rootScope.online = false;
$scope.online = $rootScope.online;
}
function onDeviceReady() {
$scope.$apply(function() {
alert('device is ready'); //Its Reaching here fine
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
$scope.deviceReady = true;
});
}
});
It seems like are onDeviceReady
this function is triggering well but after that i can reach to onOnline
function.
Is there is any another method for invoking the deviceready function in angularjs.
Thank you!
Upvotes: 0
Views: 449
Reputation: 1618
the answer i find by myself. And it was very easy. Angular has its own way to figure this out. Here is what you have to do only.
function onDeviceReady() {
alert(navigator.network.connection.type);
}
and this will tell you the connection type.
Upvotes: 1