Hi,
I on android 4.4 (lg nexus 4) - Cordova 3.5.0 - cordova-plugin-network-information (tried: 0.2.9 / master version="0.2.10-dev)
I have had some struggle with $cordovaNetwork raising TypeError: Cannot read property ‘type’ of undefined for example with this controller:
starterControllers
.controller('ConnectionCtrl', [
'$scope',
'$log',
'$cordovaNetwork',
function($scope, $log, $cordovaNetwork) {
var connectionType = 'undefined';
$scope.connectiontype = connectionType;
try {
$log.log($cordovaNetwork.getNetwork());
$scope.connectiontype = $cordovaNetwork.getNetwork();
} catch (e) {
// probably:
// ->
// TypeError: Cannot read property 'type' of undefined
// at Object.getNetwork (file:///android_asset/www/lib/ng-cordova/dist/ng-cordova.js:851:34)
// ...
$log.log('$cordovaNetwork.getNetwork()', e);
};
$scope.connectionType = function () {
$scope.connectiontype = $cordovaNetwork.getNetwork();
};
}]);
full example here: https://github.com/pellekrogholt/ionic_cordova_example_app/tree/basic_ng_cordova
so my questions are:
- have others experienced this as well? and/or how do you use the ngCordova / $cordovaNetwork?
- can i / we safely expect the navigator to be in place within a controller ?
- if not should the navigator be wrapped - used with a promise etc? (I have naively tried it out a promises-approach here without being able to solve the problem: https://github.com/pellekrogholt/ng-cordova/blob/navigator_connection_w_promises_ticket_60/src/plugins/network.js)
- or is the deviceready event simply not enough to ensure we have navigator.connection - should i instead listen for online/offline event (https://github.com/apache/cordova-plugin-network-information/blob/master/doc/index.md) ?
for the interested reader: the long story of the above can be here: https://github.com/driftyco/ng-cordova/issues/60
thx!
//
pelle