简体   繁体   English

错误:[$ injector:nomod]模块“ chart.js”不可用

[英]Error: [$injector:nomod] Module 'chart.js' is not available

I am trying to use angular-chart.js in my application, though i'm getting the following error: 我正在尝试在应用程序中使用angular-chart.js ,尽管出现以下错误:

Error: [$injector:nomod] Module 'chart.js' is not available

I have followed suggestions from other questions to include Chart.js before angular-chart.js in the html file, though this didn't work for me. 我遵循了其他问题的建议,在HTML文件中的angular-chart.js之前包含Chart.js,尽管这对我不起作用。

Here are the versions of the libraries i've installed: 这是我安装的库的版本:

角度图,chart.js和angular的版本

Here is my directory structure : 这是我的目录结构

 app/
 ----libs/
 ------Chart.js/
 ----------src/
 ------------chart.js
 ------angular-chart.js/
 --------dist/
 ----------angular-chart.js
 ----------angular-chart.css
 --index.html

Here is the link to the libraries installed with bower in my index.html : 这是我的index.html中以bower安装的库的链接:

<!-- Import the graph library -->
<script src="../libs/Chart.js/src/chart.js"></script>
<script src="../libs/angular-chart.js/dist/angular-chart.js" xmlns="http://www.w3.org/1999/html"></script>

<!-- CSS too -->
<link rel="stylesheet" href="../libs/angular-chart.js/dist/angular-chart.css">

I am trying to inject chart.js module into my controller like so: 我试图像这样将chart.js模块注入到我的控制器中

angular.module('DeviceCtrl', ['chart.js']).controller('DeviceController', function($routeParams, $scope, $http) { }

Any suggestions? 有什么建议么? Thanks! 谢谢!

The error seems to indicate that angular-chart.js is not loaded before your script is executed, you need to load it after angular and chart.js are loaded but before your script is executed. 该错误似乎表明在执行脚本之前未加载angular-chart.js,您需要在加载angular和chart.js之后但在执行脚本之前先加载它。

Nit: css should be loaded at the top of the html whereas javascript files should be loaded at the bottom after the body close tag. Nit:css应该加载在html的顶部,而javascript文件应该加载在body close标签之后的底部。

Can you provide a complete repro step using this template ? 您可以使用此模板提供完整的复制步骤吗?

I'm not familiar with the angular-chart library, but I see a few issues with what you've got so far. 我不熟悉angular-chart库,但是到目前为止我发现了一些问题。 First, the script tag for the angular-chart has a stray "xmlns" attribute that must have come from an xml document: 首先,Angular-chart的脚本标签具有一个杂散的“ xmlns”属性,该属性必须来自xml文档:

<script src="../libs/angular-chart.js/dist/angular-chart.js" xmlns="http://www.w3.org/1999/html"></script>

It probably isn't hurting anything, but I'd remove it just to make sure you're not giving the browser heartburn. 它可能不会造成任何伤害,但是我将其删除只是为了确保您不会引起浏览器的痛苦。

Next, you state 接下来,你说

I am trying to inject chart.js module into my controller 我正在尝试将chart.js模块注入到我的控制器中

The chart.js module only contains directives. chart.js模块仅包含指令。 You can't really inject it into your controller, you can only state the dependency at the module level. 您无法真正将其注入到控制器中,只能在模块级别声明依赖项。 The readme on GitHub has a good basic setup example for this set of directives. GitHub上的自述文件针对这组指令提供了一个很好的基本设置示例。 There is one factory, ChartJsFactory, that you could inject into a controller, but it looks like it's mostly meant to be used by the directives. 您可以将一个工厂ChartJsFactory注入到控制器中,但是看起来它似乎主要是由指令使用的。

The next thing I noticed is that you're including a dependency for $routeParams in the controller, but your module, DeviceCtrl, doesn't have a dependence for ngRoute included. 我注意到的第二件事是,您在控制器中包括了对$ routeParams的依赖关系,但是您的模块DeviceCtrl没有对ngRoute的依赖关系。 You could either include angular-route.js, and a dependency for 'ngRoute' in the configuration of your module, or remove $routeParams. 您可以在模块的配置中包括angular-route.js和'ngRoute'的依赖项,也可以删除$ routeParams。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的错误:[$injector:modulerr] 错误:[$injector:nomod] 模块“chart.js”不可用 - Uncaught Error: [$injector:modulerr] Error: [$injector:nomod] Module 'chart.js' is not available 错误:[$ injector:nomod]模块不可用 - Error: [$injector:nomod] Module is not available Angular JS错误:[$ injector:nomod]模块&#39;portfolioMockupApp.services&#39;不可用 - Angular JS Error: [$injector:nomod] Module 'portfolioMockupApp.services' is not available 错误:[$ injector:nomod]模块“ nvd3”不可用 - Error: [$injector:nomod] Module 'nvd3' is not available $ injector nomod模块&#39;angularFileUpload&#39;不可用 - $injector nomod Module 'angularFileUpload' is not available Angular.JS:由于以下原因而无法实例化模块路由:错误:$ injector:nomod模块“路由”不可用 - Angular.JS: Failed to instantiate module routing due to: Error: $injector:nomod Module 'routing' is not available Angular / Karma:错误:[$ injector:nomod]模块&#39;模块&#39;不可用 - Angular/Karma: Error: [$injector:nomod] Module 'module' is not available AngularJS:未捕获的错误:[$injector:nomod] 模块 _ 不可用! | 对模块的多次引用 - AngularJS: Uncaught Error: [$injector:nomod] Module _ is not available! | Multiple References to Module Angular JS,错误:[$ injector:nomod]模块&#39;blogger.posts.controllers&#39;不可用 - Angular JS, Error: [$injector:nomod] Module 'blogger.posts.controllers' is not available 错误:[$ injector:nomod]模块“ myApp.view1”不可用 - Error: [$injector:nomod] Module 'myApp.view1' is not available
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM