I am using Ionic framework to build a mobile app , i need to retrieve the device UUID i used ngCordova using the minified version from here ngCordova!
here is my main module
angular.module('starter', ['ionic','ngCordova'])
.controller('test',function($scope,$cordovaDevice){
$scope.uuid=$cordovaDevice.getUUID();
console.log($cordovaDevice)
})
$cordovaDevice is defined as object when using console.log but when using $cordovaDevice.getUUID() it gives me 'device is not defined' any help with that
You should wait until device is ready...
document.addEventListener("deviceready", function() {
$scope.isOnline = $cordovaNetwork.isOnline();
$scope.UUID = $cordovaDevice.getUUID();
}, false);
You've stated ngCordova
correctly as a module dependency. I think all you need to do is inject $cordovaDevice
into your controller with the full array syntax
.controller('test',['$scope', '$cordovaDevice', function($scope, $cordovaDevice){
$scope.uuid=$cordovaDevice.getUUID();
}])
If that doesn't work have you checked that the the plugin is loading first?
Have you installed the cordovaDevice plugin using the command?
cordova plugin add org.apache.cordova.device
This error is occurring because you are asking for a device's details, whilst you are developing on your machine.
Look at the functions. None of them will return a suitable value on your dev env. Also Cordova is built for mobile devices - they haven't created a set of handlers for local dev.
Returns the whole device object. getDevice()
Returns the Cordova version. getCordova()
Returns the name of the device's model or product. getModel()
Returns the device's operating system name. getPlatform()
Returns the device's Universally Unique Identifier. getUUID()
Returns the operating system version. getVersion()