Calling cordova network plugin inside interceptor which is inside the config( function(){} ) is failing and it says - “undefined is not an object” for window.plugin.network.type
Initially .config() executes, then .run() executes.
$ionicPlatform.ready() is inside .run() …
The flow is like this…
.config() executes //plugin is used inside $httpProvider which is inside this
.run() executes //platform.ready is in here
since config executes before platform.ready(), the plugins are still undefined and gives an error.
The main requirement here is that on every http request, I need to intercept and check if the internet connection exist, if yes, proceed with the request. If not, block the request and show an ionic popup alert.
you can also put platform ready in config … it’s not only for .run()
A better approach is how I do
create a startercontroller (default controller)
in the starter controller listen for device ready
when ready … fire event
create a .run() function to listen for the event
This way you always ensure the app is ready for device ready. So when .run() catches the event, you know device ready is … ready … and so are your plugins … after that you can continue your normal flow and even check if you’re online or offline.
Also … I had the same problem … so I created my own service to handle online/offline … so other controllers/services can use my service and not exposing the $cordovaNetwork …