$cordovaNetwork: TypeError: Cannot read property 'type' of undefined #60
Comments
@pellekrogholt I can't test on an Android, but have you tried putting the
The docs don't say anything special about Android, so it may be an issue with installing the plugin. Also check out http://stackoverflow.com/questions/15894201/checking-of-internet-connection-of-device-using-phonegap |
@pbernasconi thanks i tried to reverse the javascript files - it did unfortunately not solve the issue and still raises
"so it may be an issue with installing the plugin." do you have other suggestions ? can I say that the plugin is successfully installed when I can called it directly in the chrome console using chrome://inspect device or in the code for example a angular controller:
I don't understand why it works(tm) there and not inside the ngCordova.... any further hints/ suggestions warmly welcome... |
Strange, I have it working on my iPhone using ngCordova. I'm thinking it's an issue with cordova or the plugin, and not ngCordova. |
… Cordova service - both approaches raises 'type' of undefined for the navigator.connection.type because navigator.connection at some point when connection is not defined yet - even if 'deviceready' event have been fired - long story: ionic-team/ng-cordova#60
… the ionic-team#60 - ensure demo app uses current ngCordova.js and set to newest ionic beta release
@pbernasconi / others ok it doesn't seem to be an issue with cordova (3.5.0) / cordova-plugin-network-information (tried: 0.2.9 / master version="0.2.10-dev) controller example use casei have done some more investigation on it and the odd thing is that when its called within a scope function call navigator.connection.type works(tm) but within init of controller it raises the mentioned type error - for example this controller:
full example here: https://github.com/pellekrogholt/ionic_cordova_example_app/tree/basic_ng_cordova ngCordova $cordovaNetwork using promisesif have naively also tried an approach where I wrapped the network / navigator in a promise (inspirred by the ng-book https://www.ng-book.com): motivation: for curiosity and a naive thought that it was a solution but i doubt that now ? because it seems like we at an early stage have the navigator but withouth the navigator.connection ... more to come... |
Hi! I just remember this : https://gist.github.com/welcoMattic/c6415563d6607fbedf3e I wrote this piece of code during the beta-5 of Ionic, for a student project. It may be already good ;) |
@pellekrogholt did you resolve this issue? I think you may have to wrap the network call in a
|
I have a similar issue where I'm trying to hide the splashscreen and get the preferred language in module.run. This code always print both error and stacktrace even if the plugins are installed. .run(function($ionicPlatform, $cordovaSplashscreen, $cordovaGlobalization) {
$ionicPlatform.ready(function() {
try {
$cordovaSplashscreen.hide();
} catch(e) {
console.log(e.stack);
}
try {
$cordovaGlobalization.getPreferredLanguage().then(function(lang) {
$translate.preferedLanguage(lang);
});
} catch(e) {
console.log(e.stack);
}
});
}]) I get the following output using logcat
I still get the same error if I wrap the calls in a $timeout of 1 sec. |
My bad, I accidentally commented |
@kristianbenoit problem fixed? can I close this issue? |
That is all good with me, @pellekrogholt issue resolved ? |
Hello @pellekrogholt I'm using ionic and getting the same error with NativeAudio plugin: Uncaught TypeError: angular.module('ngCordova.plugins.nativeAudio', []) .factory('$cordovaNativeAudio', ['$q', '$window', function ($q, $window) {
|
Make sure you call this inside a $ionicPlatform.ready(...). If you dont, cordova plugins might not be initialized => $window.plugins might be undefined yet. |
Also check out the Common Issues in the docs, right after the install paragraph. |
@pbernasconi yes just close the issue - at the point of writing the issue - it was not clear to me that the call had to be wrapped with the $ionicPlatform.ready(...) |
I am also facing the same issue. This is my controller .controller('MapCtrl', ['$scope', '$rootScope', '$cordovaNetwork',
]); |
( function ()
{
'use strict';
angular.module( 'ouNow.core' )
.factory( 'ConnectionDetectiorService', ConnectionDetectiorService );
ConnectionDetectiorService.$inject = ['$cordovaNetwork'];
function ConnectionDetectiorService($cordovaNetwork)
{
var service = {
thereIsCellConnection: thereIsCellConnection,
thereIsWiFiConnection: thereIsWiFiConnection,
};
return service;
function thereIsCellConnection() {
console.log('to detect');
console.log($cordovaNetwork.getNetwork());
}
function thereIsWiFiConnection() {
// body...
}
} I got: TypeError: Cannot read property 'type' of undefined I tried on nexus 6. Ionic 1.1.0 |
Hey guys! I've got a solution! Start studying native iOS and Android! LOL #sadbuttrue |
@vitorventurin oh sure that's the solution. Not all my clients want to pay for both IOS and Android development. #sadbuttrue |
i agree with you @alloyking. i recommend ionic for simple projects but every app with low-level features are problematic. keep rockin'!!! |
@vitorventurin I like hugs! Thanks for that. :) |
@alloyking i am from Brazil. everyone here loves hugs. haha. you are welcome. https://www.youtube.com/watch?v=izGwDsrQ1eQ |
guys...lets not get personal. I still cant find a fix for the original issue/error. $cordovaNetwork.isOnline() |
any solution? |
This one worked for me, use
|
Ok, my error was because I had a code outside of the "$ionicPlatform.ready". Just is check all lines. |
I had same problem. This plugin not work at browser, only on device. So instead:
try
|
hi,
i'm using current master (7980897) of ng-cordova and like to use $cordovaNetwork in a login controller for example:
when i deploy to an android (4.4) nexus 4 device i get a blank screen.
then with chrome://inspect device - i get the following in the console:
"ng-cordova.js:793:34" ->
but i can successfully in console do:
just for the record in the app.js where i load loginControllers i have ngCordova as a dependency:
sorry if its not a error related to ng-cordova ....
//
pelle
The text was updated successfully, but these errors were encountered: