Which is the best way to check internet using network plugin ?
I don’t know if it’s the best way, but here is how I do, in my app.js
var online = false;
angular.module('BH', ['ngCordova', 'ionic', 'BH.controllers', 'BH.services', 'BH.directives', 'LocalForageModule'])
.run(function($ionicPlatform, $state, $rootScope, $window, $cordovaNetwork) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// HERE IT IS
$window.setInterval(function() {
online = $cordovaNetwork.isOnline() ? true : false;
$rootScope.$apply();
}, 500);
} else {
online = true;
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})