I have an AngularJS Cordova application and everything is going really well at the moment. My next step is to add Cordova plugins to the application such as Cordova Connect plugin to check if the network connection is on and listen to network events.
The plan is to listen to these network events and ask the Connect plugin if the device has a connection to the internet, if not I will redirect to an error page.
I'm struggling to find a place in my AngularJS application where to register these events on application startup.
Should they be in the main run block, config block or inside some kind of factory/service/provider?
Where are you guys putting these outside-AngularJS device events?
fx.
document.addEventListener("online", yourCallbackFunction, false);
I have it myModule.run my app.js and works just great, I actually have also other cordova events there.
MyModule.run(function ($rootScope, $http, dataService, $window, $q, $location, localize) {
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
//Initialize anything you need to. aka: Google analytics.
//Set other evens you need to listen to.
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
}
}
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With