今天,我濒临精神错乱。

我的目标只是添加一个插件ngCordova(在此示例中:cordova-plugin-device)。并做了一些工作。

我的出发点是项目Ionic选项卡,仅此而已。

按照收到的建议,我首先进入ngCordova网站,然后构建一个仅包含我所需要(通过设备)的custom-ng cordova.js。

我将集成到您的项目位置:/www/lib/ngCordova/dist/ng-cordova.js。

我将index.html更改如下:

...
<!-- 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>...


我在应用程序模块中进行了依赖项注入,如下所示:

   angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngCordova'])


最后,我修改控制器“ DashCtrl”以集成插件:

 .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;

          });

  });
})


我在浏览器中(在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.


奇怪的是,即使我不执行任何代码,只要执行以下操作:

bower install ngCordova --save


它会下载完整版的ngCordova,在那里,一切正常。

我真的看不出我的错误在哪里。我希望你们中间有人能帮助我理解。

感谢您花时间阅读我的信息和花时间回答(并为我的英语打断感到抱歉)。

最佳答案

这是构建系统中的错误。

打开ngCordova.js文件并进行更改

    angular.module('ngCordova.plugins', [
      'device'
    ]);




    angular.module('ngCordova.plugins', [
      'ngCordova.plugins.device'
    ]);

08-06 05:07