错误:[$injector:nomod] Module 'nvd3'不可用

Error: [$injector:nomod] Module 'nvd3' is not available

本文关键字:nvd3 Module injector nomod 错误      更新时间:2023-09-26

我正在尝试实现这个Angular-nvD3图表。到目前为止,我有以下代码:

在我的主index.html我有以下脚本包括:

    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/d3/d3.js"></script>
    <script src="bower_components/nvd3/nv.d3.js"></script>
    <script src="bower_components/angular-nvd3/dist/angular-nvd3.js"></script>
    <script src="bower_components/angularjs-nvd3-directives/dist/angularjs-nvd3-directives.js"></script>

控制器:

'use strict';
/**
* @ngdoc function
* @name myApp.controller:DashboardCtrl
* @description
* # DashboardCtrl
* Controller of the myApp
*/
angular.module('myApp')
  .controller('DashboardCtrl', function ($scope) {
   // init data and option params for the chart
});

应用程序:

var myApp= angular
  .module('myApp', ["nvd3"])
HTML视图:

<div ng-app="myApp">
    <div ng-controller="DashboardCtrl">
        <nvd3 options="options" data="data"></nvd3>
    </div>
</div>

我希望我包括所有相关的部分。

当我运行我的UI应用程序时,我得到这个错误:

Error: [$injector:nomod] Module 'nvd3' is not available

你知道我错过了什么吗?

此处回答:https://stackoverflow.com/a/37196430/3414722

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