Accepted answer


ngondestroy() {

in your productdetailcomponent shoud do the trick.

the problem here is that if you have multiple chart components visible at the same time, the plugin will be visible in all the other charts.

the better fix:

  1. register the plugin only once, outside of nginit... directly in the module file or somewhere globally. this will impact all the charts in the entire application but will make it unnecessary to unregister it so it is clear that it's something global that impacts all charts.

  2. create your own wrapper component/directive over chart.js (or a pull request for angular2-chartjs) that can accept a plugins input and pass it to the chart constructor var chart1 = new chart(ctx, { plugins: [plugin] }); this will allow you to have a chart with the plugin and a chart without it, so no need to register/unregister global plugins.

Related Query

More Query from same tag