0


I'm trying to use cardIO plugin with ngCordova, but I'm getting this error:

Error: [$injector:unpr] Unknown provider: $cordovaNgCardIOProvider <- $cordovaNgCardIO <- SoldeCtrl

Usually this means that a dependency is not injected but I don't think it's the case here:

var app = angular.module('mDinar', ['ionic', 'ngCordova']);
app.controller('SoldeCtrl', function($scope, $cordovaNgCardIO, $cordovaToast) {
    $scope.currentSolde = 50;
    $scope.ajoutCompte = function() {
        $cordovaNgCardIO.scanCard();
    }
});

...
<div class="card">
  <div class="item item-text-wrap">
    <button id="scanBtn" class="button button-balanced icon-left ion-plus-circled" ng-click="ajoutCompte()">Ajouter un compte</button>
  </div>
</div>
...

ngCordova lib (github):

/* globals CardIO: true */
angular.module('ngCordova.plugins.cardIO', [])

  .provider(
  '$cordovaNgCardIO', [function () {
/* */
  }]
);

I don't know what I'm missing, please help.

Fourat
  • 2,366
  • 4
  • 38
  • 53
  • Does it make a difference if you explicitly add 'ngCordova.plugins.cardIO' as dependency to 'mDinar'? – Ricconnect Aug 31 '15 at 08:36
  • @Ricconnect but I need the scanCard function of the get method :/ – Fourat Aug 31 '15 at 08:56
  • Maybe I do not understand correctly, but to clarify i meant to replace `angular.module('mDinar', ['ionic', 'ngCordova']` with `angular.module('mDinar', ['ionic', 'ngCordova', 'ngCordova.plugins.cardIO']` – Ricconnect Aug 31 '15 at 09:36
  • @Ricconnect the thing is that ngCordova was created to avoid that kind of injections – Fourat Aug 31 '15 at 09:40
  • I am sorry, I did not get that. Have you checked while running in the browser that the correct files are loaded with the correct modules? I know it is an obvious question to ask, but there seems nothing wrong with your code above. – Ricconnect Aug 31 '15 at 09:54
  • Yes I checked ! ng-corova.js is loaded – Fourat Aug 31 '15 at 09:57
  • @Ricconnect adding `'ngCordova.plugins.cardIO' ` and `$ionicPlatform.ready(..) ` solved it. Answer the question so you can get the bounty. Thank you – Fourat Aug 31 '15 at 20:41

1 Answers1

2

You could add 'ngCordova.plugins.cardIO' as explicit dependency to 'mDinar', as I stated in the comments above.

You also needed to wait till the deviceReady event was fired as you noted in your comment, to make sure the plugins are loaded when tried to use $cordovaNgCardIO in your controller.

Ricconnect
  • 1,089
  • 5
  • 25