I have this piece of code in order to recognize/get the device information.
ionic.Platform.ready(function() {
// will execute when device is ready, or immediately if the device is already ready.
$scope.deviceInformation = ionic.Platform.device();
$scope.currentPlatform = ionic.Platform.platform();
$scope.currentPlatformVersion = ionic.Platform.version();
});
as per the documentation given Here.
The ionic.Platform.device();
will return object that is returned to it by cordova. So in the object of cordova the object should contain information of uuid, version, model etc. The documentation is Here
So i tried to get the uuid and model from the object deviceInformation
and built and seen the app in mobile, then it shows me undefined
in the alert.
I have shown it like this:
$scope.getDeviceInfo = function() {
alert($scope.deviceInformation.uuid);
}
How can i get the details of object returned my cordova to ionic??
You have assigned the value to a Javascript variable named
deviceInformation
. So you won't get access to AngularJs'$scope.deviceInformation
.Change your
var
to$scope
:You could also use
alert(deviceInformation.uuid);
but you should stick to$scope
in AngularJS, because it allows simple binding with the HTML using expressions.I got this by simply using following code in device ready function
I was suffering with the same problem. I got what you need after long search->try->implement->erase->new try cycle. Though i followed ng-cordova plugins, i came to know that adding ng-cordova.js will not make it easy to resolve the plugin problem bcoz it just contain the initialization of plugins that are supported by the ng-cordova on its website. I have followed the steps given Here on native cordova site
Point to note here is ng-cordova.js internally calls the methods and API's od native cordova so it is very important to install the cordova plugins separately even after you install the ng-cordova.js. Then i initialized the device in
app.module
:and i called the method in my intro controller:
That gave me all that i need....
The solution is simple