Problem to use ngCordova : "device is not defined"


I tried a lot of solutions I found to solve my issue but probably not the good one. Hope someone could help me :wink:

I launched an Ionic project, and i need to get the UUID.
I installed ngCordova with bower and did all the Install paragraph said here : ngCordova website

Here is my app.js file:

I just added ngCordova at the angular.module line, and added $cordovaDevice in the run method


  • I already called the ng-cordova.js script in the index.html file.
  • The device plugin is installed

And here is my console log error :

Uncaught ReferenceError: device is not defined

Does someone have any idea to resolve it ?
Many thanks.

I place the following snuppet in $ionicPlatform.ready, like you did, i go like this and put my values in a variable that I got called appData.state. but you could put it elsewhere or to the console… hope this helps. :

if( ionic.Platform.isAndroid() ){
appdata.state.deviceModel = $cordovaDevice.getModel();
appdata.state.deviceUUID = $cordovaDevice.getUUID();
console.log(“Is not Android”);
appdata.state.deviceModel = “windows”;
appdata.state.deviceUUID = “testUUID”;

Thank you for your answer boltex.
Unfortunately, your example don’t work for me. That tells me the same thing : device is not defined and i really don’t understand why.

Maybe i forgot something somewhere in the code. Is it possible for you to give me please a little piece of your code that works with ngCordova that i can test ?

Or someone else maybe has another idea ?

Many thanks.

Just curious, did you add ngcordova before or after cordova.js? It does make a difference.

Hi Mike,

I added ngCordova before cordova.js. I reproduced all the step described in the documentation but that didn’t work …
I found a solution to get around my issue but this is not the one i wanted.

I now launch the command phonegap serve rather than ionic serve. I put the .cordova folder (generated with phonegap) at the root of the project generated by ionic. And i don’t use ngCordova anymore, but the “native” plugins give by phonegap.

If you have any solution to help me to use ngCordova with ionic, i’d be delighted to hear :smile:

Alright, soo none of the cordova plugins will work with ionic serve of phonegap serve. They need to be installed on the device in order to work.

1 Like

yeah like mhartington said: plug in your android phone into a usb port on your computer, enable debug on your phone and type: ionic run android

the code i gave you tests to see if it’s on a phone or on the browser before checking for the uuid.

1 Like

If you did a custom download of ngCordova, there are several errors in their output that you will need to fix, I got that error because of the module naming being incorrect.

I have the same problem all I am trying to do is
And the alert is Device is not defined. Even when I run it on my android phone.

the top is like this to allow ngCordova and $cordovaDevice

.controller(‘httpLogin’, [’$scope’,’$http’,‘DSP_URL’,’$ionicLoading’,’$cordovaDevice’, function ($scope,$http,DSP_URL,$ionicLoading,$cordovaDevice) {

and my library loads are in this order

I must be missing a step to make this work.

1 Like

@alindzon, make sure you run that code after ionicplatform ready :slight_smile:

1 Like

I tried your solution @boltex and that works. I only tried the “ionic serve” command, that’s why that didn’t work.
Many thanks for your help :wink:

offtopic: how do you confirm a selected option of a select control if you call Keyboard.hideAccessoryBar(true)? It seems a bit problematic. We regret to manage a virtual keyboard at all, as many issues are raised after that.

Can you provide a detail way of how you fixed this problem? I have the same ‘device is not defined’ error message when trying to collect the device info.

1 Like