ngCordova not working properly


#1

I am trying to use the Device Plugin of the ngCordova module in a test Android app. I tried to get the model name, so I defined it as a controller method and called the method on click of a button. It worked, but, when I tried to use data binding from my view, it does not work.

My code:

This doesn’t work when I bind it on my view like this

<p>{{showDevice.model}}</p>
$scope.showDevice = {
  'model': $cordovaDevice.getModel()
};

It works when I define it on my showDevice as a function and call it from a button.

$scope.showDevice = function() {
  alert($cordovaDevice.getModel());
};

Why is the one defined as a controller method working and the other with data binding is not? Thanks!


#2

This might be the result of bootstrapping your Ionic app before Cordova has finished initializing: calls to Cordova plugins will fail silently until Cordova is ready.

We had a similar issue with $cordovaStatusbar, and fixed it by removing the ng-app="myApp" directive and replacing it with:

ionic.Platform.ready(function() {
    angular.bootstrap(document, ['myApp']);
});

(in a normal <script> at the bottom of index.html)

More information: