TypeError: Cannot read property 'type' of undefined

I have problems in $ cordovaNetwork.
Always appears the error:

TypeError: Cannot read property ‘type’ of undefined

My app.js

angular.module(‘starter’, [‘ionic’,‘ngCordova’])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})

.controller(‘MyCtrl’, function($scope, $cordovaNetwork) {
var type = $cordovaNetwork.getNetwork();

var isOnline = $cordovaNetwork.isOnline();

var isOffline = $cordovaNetwork.isOffline();
});

Could you be more specific to where the line occurs? (file name and line number)

Dude, I had some issues like this, I can suggest you:

  1. Ensure that ngCordova is called BEFORE cordova
  2. Use ngCordova zip from github, the custom generated failed to me
  3. Check if the plugin is properly installed (not ngCordova, but the network plugin

I think those were the steps that saved me.

2 Likes

I tried the steps but the error persists
follows the error.

Console was cleared ripple.js:37
Ripple :: Environment Warming Up (Tea. Earl Gray. Hot.) ripple.js:37
GET http://192.168.0.101:8100/config.xml 404 (Not Found) ripple.js:50
cordova :: Initialization Finished (Make it so.) ripple.js:37
GET http://192.168.0.101:8100/cordova.js 404 (Not Found) (index):22
TypeError: Cannot read property ‘type’ of undefined
at Object.getNetwork (http://192.168.0.101:8100/lib/ngCordova/dist/ng-cordova.js:1139:34)
at new (http://192.168.0.101:8100/js/app.js:22:30)
at invoke (http://192.168.0.101:8100/lib/ionic/js/ionic.bundle.js:12930:17)
at Object.instantiate (http://192.168.0.101:8100/lib/ionic/js/ionic.bundle.js:12941:23)
at http://192.168.0.101:8100/lib/ionic/js/ionic.bundle.js:16195:28
at http://192.168.0.101:8100/lib/ionic/js/ionic.bundle.js:15597:34
at forEach (http://192.168.0.101:8100/lib/ionic/js/ionic.bundle.js:9358:20)
at nodeLinkFn (http://192.168.0.101:8100/lib/ionic/js/ionic.bundle.js:15584:11)
at compositeLinkFn (http://192.168.0.101:8100/lib/ionic/js/ionic.bundle.js:15042:15)
at compositeLinkFn (http://192.168.0.101:8100/lib/ionic/js/ionic.bundle.js:15045:13) ionic.bundle.js:18930
cordova :: fired deviceready event!

needed to see the source to help out :-/

My project is simple, only started in Ionic !
Sorry my english, i’m brazil.

Project Repository GitHub:
https://github.com/crucifyextreme/ionic_test

Thanks for help.

As far as I know, Ripple won’t expose a navigator.connect object. You need to either first check if cordova is present, or run it on a device.

if(window.cordova && window.cordova.plugins.Keyboard) {
var type = $cordovaNetwork.getNetwork();
}

is not possible to test in the browser?
Only in device ?

Thanks !

guys, try everything appears the same undefined error.

I tried now the status bar and appeared StatusBar is not defined!

What’s wrong?

I’m testing using the chrome ripple can this be?

Thanks.

I think so… try to use “ionic serve”

Hi.
Have same trouble…, work fine with ionic serve on browser on device (android 5.0.1) throw this.
image
$cordovaNetwork used like:
$scope.isOnline = $cordovaNetwork.isOnline();

ngCodrova included in index.html before cordova.js etc.
ngCordova v0.1.12-alpha
ionicframework v1.0.0-beta.14

SOLVED :smiley:

As suggested here on stackoverflow, ripple does not have an in-browser keyboard simulator, so once you upload your app to the device, error will be gone.

For “in-browser testing”, just comment out the section which checks if keyboard is shown