We're using ng-view in our application. Navigating to and from a view with a chart and a view without a chart I found two things happening:
- When moving from chart to non-chart, the non-chart view throws rendering errors when the browser window resizes (Chart js registers an event handler for window resize, and loops through instances to redraw them).
- The number of instances in Chart.instances increases each time the user navigates to the view containing a chart, it never decreases when user navigates away from the chart view.
The following is needed in the link function:
$scope.$on("$destroy", function(){
if (chartCreated){
chartCreated.destroy();
}
});