fusioncharts / angular-fusioncharts

Angular Component for FusionCharts JavaScript Charting Library
https://fusioncharts.github.io/angular-fusioncharts/#/ex1
Other
55 stars 37 forks source link

Cannot read property 'dispose' of undefined in ngOnDestroy #35

Closed turu-shep closed 5 years ago

turu-shep commented 5 years ago

We use many charts in app and user can switch from one chart type to another (rendered as different components of course). Also charts are rebuilded on window:resize event. If few resize event appear in a row or user switches fast from one chart to another, his console becomes filled with this messages:

image

that comes from angular-fusioncharts component, ngOnDestroy hook. Sometimes this blocks chart rendering, sometimes not (10% of cases - blocks and nothing is rendered). I believe it's trying to dispose chart config object, but if chart was not fully initialized by the time it gets destroyed, there won't be this object, so nothing to dispose.

ashok1994 commented 5 years ago

@kaname52 I tried to replicate this with the updated version , using a simple ngIf hook, couldn't able to replicate. Can you please tell which version of angular-fusioncharts you are using

turu-shep commented 5 years ago

@ashok1994 2.0.2 along with licensed fusioncharts v.3.13.1-sr.1

ashok1994 commented 5 years ago

I tried this version too, could not replicate the problem, if you can provide me with small scaled version of the example replicating the problem it'll be great @kaname52

jcanaan88 commented 5 years ago

I'm getting the same issue. Angular 7.

While chart component is initializing, quickly switch to a view that hides the chart and you get it everytime.

In my specific instance, I have buttons that change each view based on an ngSwitch.

This happens at fusioncharts.component.js.364 - the chart is undefined if you try to switch too quickly, as if it was never initialized - so adding a check to make sure there is a chart before trying to destroy it does the trick.

if(this.chartObj !== undefined){ this.chartObj.dispose(); }

Assuming there is likely a more elegant way to handle it, but this works for me for now.

vherever commented 5 years ago

@ashok1994, hi, I created a private demo repo to reproduce this error, https://github.com/vherever/fusioncharts-demo Thank you in advance!

rohanoid5 commented 5 years ago

@vherever please add me to your private repo. I'll investigate your issue.

vherever commented 5 years ago

@rohanoid5 added you too, thank you

rohanoid5 commented 5 years ago

@vherever this issue has been fixed. Please update angular-fusioncharts

turu-shep commented 5 years ago

@rohanoid5 thank you! I believe this PR can be closed now https://github.com/fusioncharts/angular-fusioncharts/pull/57 since it fixes the same issue

vherever commented 5 years ago

@rohanoid5 Thank you, it works!