Today I found myself on the edge of madness.
All I wanted to do was add a plugin called ngCordova (specifically cordova-plugin-device) to my project. It seemed simple enough.
I started with an Ionic tabs project, nothing more.
Following some advice, I visited the ngCordova website and created a custom-ng cordova.js file containing only what I needed (for device).
I integrated it into my project at: /www/lib/ngCordova/dist/ng-cordova.js.
Then, I updated my index.html like this:
...
<!-- 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 added a dependency injection to my application module like so:
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngCordova'])
Finally, I made changes to the "DashCtrl" controller to incorporate the plugin:
.controller('DashCtrl', function($ionicPlatform, $scope, $cordovaDevice) {
$ionicPlatform.ready(function() {
$scope.$apply(function() {
// sometimes binding does not work! :/
// getting device information from $cordovaDevice
var device = $cordovaDevice.getDevice();
$scope.manufacturer = device.manufacturer;
$scope.model = device.model;
$scope.platform = device.platform;
$scope.uuid = device.uuid;
});
});
})
When I checked in my browser (under Ripple), I encountered this error:
Uncaught Error: [$injector:modulerr] Failed to instantiate starter module 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 forgot to load the module. If you are registering a module, make sure to specify dependencies as the second argument.
What remains puzzling is that, even without changing anything in my code, simply running:
bower install ngCordova --save
Downloads the full version of ngCordova, and then everything works perfectly.
I'm stumped and hope someone here can help me figure out where I went wrong.
Thank you for taking the time to read my message and for any assistance you may provide (and apologies for any language errors).