【发布时间】:2016-12-25 02:16:37
【问题描述】:
我最近开始使用 angular,更具体地说是生成器 angular-fullstack (https://github.com/angular-fullstack/generator-angular-fullstack)。
我尝试使用 angular-chart-js (https://github.com/jtblin/angular-chart.js) 库在我的应用程序中显示图形,但未成功。在“app”模块依赖项中添加chart.js 时总是出错。
我做了什么:
使用命令“npm install --save angular-chart.js”(在我的应用根文件夹中)安装 angular-chart.js,我已经检查了“package.json”文件中的依赖关系。
修改 index.html 和 _index.html
<head>
<script src="../node_modules/chart.js/dist/Chart.js"></script>
<script src="../node_modules/angular-chart.js/dist/angular-chart.js"></script>
</head>
app.js
angular.module('myApp', ['chart.js']);
这个配置给了我错误
模块“chart.js”不可用!您要么拼错了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。
在我尝试了不同的配置之后
将行从 index.html 和 _index.html 移到 main.html
main.html
<script src="../../../node_modules/chart.js/dist/Chart.js"></script>
<script src="../../../node_modules/angular-chart.js/dist/angular-chart.js"></script>
以不同的方式导入库,并禁用严格模式app.js。
app.js
import chartJs from 'chart.js';
angular.module('myApp', [chartJs]);
angular.element(document)
.ready(() => {
angular.bootstrap(document, ['myApp'], {
strictDi: false
});
});
通过这个设置我得到了这个错误
错误:[$injector:modulerr] 无法实例化模块函数(上下文,配置),原因是: 错误:[$injector:unpr] 未知提供者:上下文
如果您需要更多信息,请告诉我。
提前致谢!
【问题讨论】:
标签: javascript angularjs chart.js angular-fullstack angular-chart