I am facing an issue with my Ionic app while trying to run it in offline mode. The error message "services.js:392 Uncaught TypeError: $rootScope.$on is not a function" appears when I launch the app. Can someone please explain why this is happening and what steps I should take next?
I specifically require the offline mode feature to be functional in order to submit my app to the store. One of the key functionalities that need to be disabled in offline mode is the Google Maps location dropdown.
})*/
.factory('ConnectivityMonitor', ['$ionicPopup', function($rootScope, $cordovaNetwork, $ionicPopup){
return {
isOnline: function(){
if(ionic.Platform.isWebView()){
return $cordovaNetwork.isOnline();
} else {
return navigator.onLine;
}
},
isOffline: function(){
if(ionic.Platform.isWebView()){
return !$cordovaNetwork.isOnline();
} else {
return !navigator.onLine;
}
},
startWatching: function(){
if(ionic.Platform.isWebView()){
$rootScope.$on('$cordovaNetwork:online', function(event, networkState){
console.log("Device is online");
});
$rootScope.$on('$cordovaNetwork:offline', function(event, networkState){
console.log("Device is offline");
$ionicPopup.alert({
title: 'No Internet Connection',
content: 'This app requires an internet connection.'
})
.then(function() {
//ionic.Platform.exitApp();
});
});
}
else {
...
}
}
}
}])