Today I went to the brink of insanity.
My goal is simply to include a plugin ngCordova (in this example: cordova-plugin-device). And with a little work.
My starting point is a project Ionic tabs, nothing more.
Following the advice I received I first go to the website ngCordova, and I build a custom-ng cordova.js containing only what I need (by device).
I integrates into your project location: /www/lib/ngCordova/dist/ng-cordova.js.
I change my index.html as follows:
...
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>...
I made a dependency injection in my application module like this:
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngCordova'])
And finally, I modify the controller "DashCtrl" to integrate the plugin:
.controller('DashCtrl', function($ionicPlatform, $scope, $cordovaDevice) {
$ionicPlatform.ready(function() {
$scope.$apply(function() {
// sometimes binding does not work! :/
// getting device infor from $cordovaDevice
var device = $cordovaDevice.getDevice();
$scope.manufacturer = device.manufacturer;
$scope.model = device.model;
$scope.platform = device.platform;
$scope.uuid = device.uuid;
});
});
})
And I get this error in my browser (under Ripple):
Uncaught Error: [$ injector: modulerr] Failed to instantiate starter unit due to:
Error: [$ injector: modulerr] Failed to instantiate ngCordova Module due to:
Error: [$ injector: modulerr] Failed to instantiate ngCordova.plugins Module due to:
Error: [$ injector: modulerr] Failed to instantiate the module device due to:
Error: [$ injector: nomod] Module 'device' is not available! Either you misspelled the name or it forgot to load module. If a unit Registering assurer That You Specify the dependencies as the second argument.
The strange thing is that, even without touching anything in my code, if I do a:
bower install ngCordova --save
It downloads the full version of ngCordova, and there, everything works perfectly.
I really do not see where is my mistake. I hope that someone among you will help me to understand.
Thank you for the time you took to read my message and the time you take to answer (and sorry for my broken English).
It is a bug in the build system.
Open ngCordova.js file and change
angular.module('ngCordova.plugins', [
'device'
]);
to
angular.module('ngCordova.plugins', [
'ngCordova.plugins.device'
]);