【问题标题】:$injector:modulerr] Failed to instantiate module nvd3 due to:$injector:modulerr] 无法实例化模块 nvd3,原因如下:
【发布时间】:2016-05-12 19:38:58
【问题描述】:

我关注了这个帖子: http://gonehybrid.com/bring-your-ionic-app-to-life-getting-started-with-d3-js/

我有所有的库,但不幸的是,我收到了这个错误:

Error: [$injector:modulerr] Failed to instantiate module starter due to:
[$injector:modulerr] Failed to instantiate module nvd3 due to:
[$injector:nomod] Module 'nvd3' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.5.3/$injector/nomod?p0=nvd3
minErr/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13415:12
module/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15381:17
ensure@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15305:38
module@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15379:14
loadModules/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17871:22
forEach@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13668:11
loadModules@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17855:5
loadModules/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17872:40
forEach@http://localhost:8100/lib/ionic/js/ionic

在我的 Win7 机器上的 VirtualBox 中运行 Ubuntu 14.04:

dev@dev-VirtualBox:~/code/d3Examples/www/lib$ ls
angular          angular-nvd3      angular-ui-router  ionic
angular-animate  angular-sanitize  d3                 nvd3
dev@dev-VirtualBox:~/code/d3Examples/www/lib$ 

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', [
  'ionic',
  'nvd3'
])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if (window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
  <title></title>

  <link href="lib/ionic/css/ionic.css" rel="stylesheet">
  <link href="css/style.css" rel="stylesheet">

  <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

  <!-- ionic/angularjs js -->
  <script src="lib/ionic/js/ionic.bundle.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>
  <script src=”lib/d3/d3.js”></script>
  <script src=”lib/nvd3/build/nv.d3.min.js”></script>
  <script src=”lib/angular-nvd3/dist/angular-nvd3.min.js”></script>
  <link rel=”stylesheet” href=”lib/nvd3/build/nv.d3.css”>

</head>

<body ng-app="starter">

  <ion-pane>
    <ion-header-bar class="bar-stable">
      <h1 class="title">Ionic Blank Starter</h1>
    </ion-header-bar>
    <ion-content>
    </ion-content>
  </ion-pane>
</body>

</html>

【问题讨论】:

    标签: angularjs ionic-framework nvd3.js angular-nvd3


    【解决方案1】:

    这是 javascript 的缺失依赖问题。在您的index.html 中,在加载外部库后加载您的app.js,因为 Angular 模块无法实例化 nvd3 模块,因为它不存在。

    这应该是你的index.html

    <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
      <title></title>
    
      <link href="lib/ionic/css/ionic.css" rel="stylesheet">
      <link rel=”stylesheet” href=”lib/nvd3/build/nv.d3.css”>
      <link href="css/style.css" rel="stylesheet">
    
      <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
        <link href="css/ionic.app.css" rel="stylesheet">
        -->
    
      <!-- ionic/angularjs js -->
      <script src="lib/ionic/js/ionic.bundle.js"></script>
    
      <!-- cordova script (this will be a 404 during development) -->
      <script src="cordova.js"></script>
    
      <script src=”lib/d3/d3.js”></script>
      <script src=”lib/nvd3/build/nv.d3.min.js”></script>
      <script src=”lib/angular-nvd3/dist/angular-nvd3.min.js”></script>
      <!-- your app's js -->
      <script src="js/app.js"></script>
    
    </head>
    
    <body ng-app="starter">
    
      <ion-pane>
        <ion-header-bar class="bar-stable">
          <h1 class="title">Ionic Blank Starter</h1>
        </ion-header-bar>
        <ion-content>
        </ion-content>
      </ion-pane>
    </body>
    
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2016-04-13
      • 2018-04-20
      • 2016-05-23
      • 2018-09-29
      • 2020-04-07
      • 2022-08-22
      相关资源
      最近更新 更多