我最近开始使用 Angular,更具体地说是使用 Angular-fullstack 生成器 ( https://github.com/angular-fullstack/generator-angular-fullstack )。
我尝试使用 angular-chart-js ( https://github.com/jtblin/angular-chart.js ) 库在我的应用程序中显示图表,但没有成功。当我在“app”模块依赖项中添加图表.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']);
这个配置给了我错误
Module 'chart.js' 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.
尝试不同的配置后
将行从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
});
});
通过此设置,我收到此错误
Error: [$injector:modulerr] Failed to instantiate module function (context, config) due to: Error: [$injector:unpr] Unknown provider: context
如果您需要更多信息,请告诉我。
提前致谢!
最佳答案
我发现了这个错误!!
这是我的更改
app.js
import chartJs from 'angular-chart.js';
angular.module('myApp', [chartJs]);
angular.element(document)
.ready(() => {
angular.bootstrap(document, ['myApp'], {
strictDi: true
});
});
库名称错误,我可以再次启用“严格模式”。
关于javascript - Generator-Angular-FullStack 无法添加 Angular-Chart.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39013292/