javascript - Check online or not before data load cordova -


i trying create cordova application angularjs.i using local storage , data stored after first load. if app loaded without internet,i need load data localstorage else need load internet.

 ondeviceready: function() {       isoffline = 'online' in navigator && !navigator.online;    } 

i status here,but problem , angular controller start loading data before

document.addeventlistener('deviceready', this.ondeviceready, false); 

this event triggered , how apply online offline logic angular js , cordova?

you use $watch here on 'online' in navigator && !navigator.online; evaluated on each digest cycle, , call watch function if value gets changed.

code

$scope.$watch(function(){    return 'online' in navigator && !navigator.online; }, function(newvalue, oldvalue){     if(newvalue) {//it means user online        //do code here     } }); 

Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -