0
Below is the code I’m using. It’s the standard example of the Cordova connection check function.
<script>
angular.module("contato", []);
angular.module("contato").controller("contatoCtrl", function($scope){
$scope.app = "app";
var checkConnection = function () {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
console.log('Connection type: ' + states[networkState]);
alert('Connection type: ' + states[networkState]);
};
checkConnection();
});
</script>
However, I have the following mistake:
angular.js:12450 TypeError: Cannot read property 'type' of undefined
at checkConnection (index.html:50)
at new <anonymous> (index.html:67)
at Object.invoke (angular.js:4476)
at extend.instance (angular.js:9127)
at nodeLinkFn (angular.js:8239)
at compositeLinkFn (angular.js:7671)
at publicLinkFn (angular.js:7546)
at angular.js:1662
at Scope.$eval (angular.js:15922)
at Scope.$apply (angular.js:16022)
Note>: If the solution is to remove the function from the angle and perform as a normal javascript function, you are also welcome
Are you trying to radar this function in a browser or on a mobile device ? If it is in a browser the error is occurring because Cordova is not detected by the browser, try running on a device and see if the error persists.
– 1fabiopereira
In both the error persists
– Lucas Torres
You could send the part of the code that imports Cordova to your project. I suggest you take a look at ng-Cordova and make sure that the network plugin is installed in your project
– 1fabiopereira
I’m not using Ordova for angular. I’m using pure Ordova
– Lucas Torres