Skip to content

Directives need to destroy chart when directive is destroyed #68

@speshy

Description

@speshy

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();
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions