ngCordova $cordovaNetwork, navigator / navigator.connection and ionic deviceready?


#1

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:

for the interested reader: the long story of the above can be here: https://github.com/driftyco/ng-cordova/issues/60

thx!

//

pelle


Unknown provider: $cordovaNetworkProvider error
#2

looks like you forgot to include ‘ngCordova’ in your app initialization

angular.module('starter', [
  'ionic',
  'ngCordova',
  'starter.controllers'
])

#3

hi hannuraina,

thanks a lot for your feedback and suggestion.

i include ngCordova in the controllers module:

  var starterControllers  = angular.module('starter.controllers', ['appServices', 'ngCordova']);

though i tried doing it globally in the app.js as well but that didn’t solve my issues with navigator.connection.type raisng type error - just let me know if im wrong on this…
//

pelle