Reproduction of the problem
Hi, I'm trying to use ng2-charts in an ionic 2 project and I get the following error:
Error: ng2-charts configuration issue: Embedding Chart.js lib is mandatory
Versions:
Unfortunately the workarounds on #458 didn't help. Are there any workarounds to this problem?
Thank you!
adding
import '../../node_modules/chart.js/dist/Chart.bundle.min.js'; // and
import { ChartsModule } from 'ng2-charts/components/charts/charts';
to the app.module.ts fixed the problem. I guess this bug makes more sense on the ionic github repository, since it seems to be that ionic 2 isn't properly including some packages.
@martinpinto
We should not include directly in app.module like the way you did for chart.js
chart.js doesn't support commonjs modules so added them in the project.config file under NPM_DEPENDENCIES
the best way i prefer is this.
` this.NPM_DEPENDENCIES = [
...this.NPM_DEPENDENCIES,
{src: 'jquery/dist/jquery.min.js', inject: 'libs'},
{src: 'lodash/lodash.min.js', inject: 'libs'},
{src: 'chart.js/dist/Chart.min.js', inject: 'libs'},
];`
libs, the dependency will be injected into the <!-- libs:js --> section of the index file.
if you are using an angular-seed this is the best practice to add external libs
Hi,
I am gettting error in Ionic 2 application using chart.js
Uncaught Error: Can't resolve all parameters for Chart: (?, ?)
Most helpful comment
adding
to the
app.module.tsfixed the problem. I guess this bug makes more sense on the ionic github repository, since it seems to be that ionic 2 isn't properly including some packages.