【发布时间】:2017-08-23 13:36:29
【问题描述】:
我想在我的 Angular 项目中使用 Chart.js。 在以前的 Angular2 版本中,我一直在使用 'chart.loader.ts' 做得很好,它具有:
export const { Chart } = require('chart.js');
然后在我刚才的组件代码中
import { Chart } from './chart.loader';
但升级到 cli 1.0.0 和 Angular 4 后,我收到错误消息:“找不到名称 'require'”。
重现错误:
ng new newapp
cd newapp
npm install chart.js --save
echo "export const { Chart } = require('chart.js');" >> src/app/chart.loader.ts
ng serve
在我的“tsconfig.json”中,我有
"typeRoots": [
"node_modules/@types"
],
在 'node_modules/@types/node/index.d.ts' 中有:
declare var require: NodeRequire;
所以我很困惑。
顺便说一句,我经常遇到警告:
[tslint] The selector of the component "OverviewComponent" should have prefix "app"(component-selector)
虽然我在“.angular-cli.json”中设置了“前缀”:“”。会不会是因为从 'angular-cli.json' 变成 '.angular-cli.json' 的原因?
【问题讨论】:
-
问题出在您的 tsconfig.json 文件中。在此处查看解决方案:stackoverflow.com/questions/31173738/…
-
@IndyWill 谢谢,实际上它应该在 src/tsconfig.app.json 中。你能把这个写成答案吗?
-
对于电子 + 角度 2/4,请参阅:stackoverflow.com/a/47364843/5248229
标签: angular angular-cli