Cannot use ngCordova plugins in services

When I call cordovaGlobalization in controllers, it works fine, but when I call it in Services, it raises an error that cordovaGlobaliztion is undefined!

The following code works fine.

.controller('SettingsController', function($scope, $cordovaGlobalization) {

  $cordovaGlobalization.getLocaleName().then(
    function(result) {
      console.log('getLocalName()');
      console.log(result.value);
    },
    function(error) {
      alert('error with getLocaleName');
  });
})

But this one does not work

.factory('AppService', function($cordovaGlobalization) {
  return {
    country: function() {
      $cordovaGlobalization.getLocaleName().then(
        function(result) {
          console.log('getLocalName()');
          console.log(result.value);
        },
        function(error) {
          alert('error with getLocaleName');
        });
      }
  })
1 Like

Do you have ng-cordova.js included before or after cordova?
It should be included before.

Here are the scripts in the order I load them

<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ng-cordova.js"></script>
<script src="lib/angular-touch.min.js"></script>
<script src="lib/angular-translate.min.js"></script>
<script src="cordova.js"></script>
<script src="js/services.js"></script>

I’m actually having an error getting it to work in a controller. I’m getting undefined as well.

Were you ever able to solve this? I am having the same problem.

Any updates? I am still having the same problem.
@mhartington can you please cheack this?