Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AngularJS directive memory leak #5

Open
ufocoder opened this issue Oct 14, 2017 · 0 comments
Open

AngularJS directive memory leak #5

ufocoder opened this issue Oct 14, 2017 · 0 comments

Comments

@ufocoder
Copy link
Owner

Project need an example for AngularJS directive memory leak with URL to live example on JSFiddle (or something like that)

For example there's a memory leak

function(scope, element, attrs) {  
  element.on('click', function() {
    scope.selected = true
  })
}

And it could be fixed like the following:

function(scope, element, attrs) {  
  element.on('click', function() {
    scope.selected = true
  })
  scope.$on('$destroy', function() {
    element.off() // deregister all event handlers
  })
}

By the way for more information about memory leaks in AngularJS you could read here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant