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


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:

.controller('ConnectionCtrl', [
  function($scope, $log, $cordovaNetwork) {

    var connectionType = 'undefined';
    $scope.connectiontype = connectionType;

    try {
      $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:

so my questions are:

for the interested reader: the long story of the above can be here:




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

angular.module('starter', [

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…