Not able to retieve device model using ngCordova


#1

I have created a blank ionic project. Using ngCordova, I am trying to retrieve device model.

In my app.js, I added a controller after ionic platform is ready:

.controller('TodoCtrl',function($scope, $cordovaDevice){
    console.log('Retrieving device');
    try {
        $scope.model = $cordovaDevice.getModel();
    } catch (err) {
        console.log('error ' + err.message);
    }
})

In my index.html, I added a placeholder inside ion-content:

<ion-content ng-controller="TodoCtrl">
      <p>{{model}}</p>
</ion-content>

Running on Android device and FirefoxOS simulator, the err.message is:

"error device is not defined" 

#2

You added plugin ?

cordova plugin add org.apache.cordova.device


#3

Yah added.

cordova plugin add org.apache.cordova.device
Fetching plugin "org.apache.cordova.device" via plugin registry
Plugin "org.apache.cordova.device" already installed on firefoxos.

#4

This info help, but only work on FirefoxOS, not Android:

http://www.raymondcamden.com/2014/8/16/Ionic-and-Cordovas-DeviceReady–My-Solution


#5

I think the problem is I am retrieving device info before it is initialized by cordova.js:

"initializing device" controllers.js:5
"adding proxy for Device" cordova.js:846

Is this a bug?