我希望在我的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'中设置了"prefix": "",但是是不是因为从'angular-cli.json'更改为'.angular-cli.json'导致的呢?结果:
尽管我在'.angular-cli.json'中设置了"prefix": "",但是是否因为从'angular-cli.json'更改为'.angular-cli.json'导致问题?