I want to use Chart.js within my Angular project. In previous Angular2 versions, I have been doing this well by using a 'chart.loader.ts' which has:
export const { Chart } = require('chart.js');
Then in the component code I just
import { Chart } from './chart.loader';
But after upgrading to cli 1.0.0 and Angular 4, I get the error: "Cannot find name 'require'".
To reproduce the error:
ng new newapp
cd newapp
npm install chart.js --save
echo "export const { Chart } = require('chart.js');" >> src/app/chart.loader.ts
ng serve
In my 'tsconfig.json', I have
"typeRoots": [
"node_modules/@types"
],
And in 'node_modules/@types/node/index.d.ts' there is:
declare var require: NodeRequire;
So I'm confused.
BTW, I constantly encounter the warning:
[tslint] The selector of the component "OverviewComponent" should have prefix "app"(component-selector)
Though I have set the "prefix": "" in my '.angular-cli.json'. Could it because changing from 'angular-cli.json' to '.angular-cli.json' the cause?