1

I'm writing an angular app, and I'm using addEventListener for several events. My question is, when the route changes, are the event listeners still active? And if so do they need to be manually removed to prevent memory leaks?

I'm targeting modern browsers: Safari, Firefox, Chrome, IE >= 10

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
richbai90
  • 4,994
  • 4
  • 50
  • 85
  • Why are you using `addEventListener` in an Angular app when it already has so many event methods available to it? – Josh Burgess Aug 14 '15 at 20:10
  • 1
    I don't really have an answer for that. I have a weird habit of trying to use vanilla js whenever its available. So to that end, does .on need to be unbound on DOM changes? – richbai90 Aug 14 '15 at 20:14

1 Answers1

0

When using 'vanilla js' to bind events to the dom they will not be unbound, so you should manually do this. I see no reason why you would bind events like this when using angular though.

A nice post explaining everything: https://stackoverflow.com/a/27016855/5223929

Community
  • 1
  • 1
Wout De Rooms
  • 647
  • 4
  • 10