Zabs
Zabs

Reputation: 14142

“device is not defined” : Ionic/Cordova app - trying to collect device model/manufacturer

I have installed the cordova plugin 'cordova-plugin-device' and am trying to retrieve the device object to get the model and manufacturer for the device running my app. https://www.npmjs.com/package/cordova-plugin-device

Currently my app is split into sections, my 'about' section controller looks like follows:

// coffeescript code

angular.module('aboutPageController', ['ionic', 'ngCordova'])
.controller 'aboutPage',['$scope', '$ionicPlatform', '$cordovaDevice', ($scope, $ionicPlatform, $cordovaDevice) ->
$scope.aboutTxt = 'some text'
$ionicPlatform.ready ->
  $scope.$apply ->    
  $scope.aboutTxt = 'new text'
  device = $cordovaDevice.getDevice()
  console.log(device)
  deviceInformation = $ionicPlatform.device()
  $scope.aboutTxt = deviceInformation.model
  return
 return
return
]

My App

<!-- ionic/angularjs js -->
<script src="js/ionic.bundle.js"></script>
<script src="js/angular-resource.js"></script>
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/templates.js"></script>

I am currently getting the following error device

ReferenceError: device is not defined

in ionic.bundle.js:25642 ReferenceError: device is not defined

Upvotes: 1

Views: 3208

Answers (1)

user3769694
user3769694

Reputation: 222

You must wait for cordova to send the deviceready event. Otherwise this Reference error will be coming. You should add an event Listener for deviceready.

This is my Understanding.

Upvotes: 2

Related Questions