can please help?
i trying check when internet conectivity lost in ionic project, working fine event fires twice in row reason. below code in app.js in $ionicplatform.ready:
if (window.connection) { $rootscope.$on('$cordovanetwork:online', function (event, networkstate) { console.log('we online'); }); $rootscope.$on('$cordovanetwork:offline', function (event, networkstate) { console.log('we offline'); }); }
like said works fires twice in row, when want display popup when internet connection lost displayed twice.
i checked ionic forum , found guy similar problem no 1 gave him exact answer: http://forum.ionicframework.com
this workaround using state dummy var
var isonline = true; if (window.connection) { $rootscope.$on('$cordovanetwork:online', function (event, networkstate) { if(isonline) return; isonline = true; console.log('we online'); }); $rootscope.$on('$cordovanetwork:offline', function (event, networkstate) { if(!isonline) return; isonline = false; console.log('we offline'); }); }
Comments
Post a Comment