Rothschild Rothschild - 7 months ago 70
AngularJS Question

Binding scroll event - how to unbind?

I am using the following code to bind scroll on a page;

angular.element($window).bind("scroll", function () {});

The issue I am having is that the binding is persisting when I navigate away from the page. How do I release a binding? I tried assigning it to a variable and calling said variable in the binding, like with
but that didn't work.


First namespace your scroll event, so you can remove it specifically when the need arises: angular.element($window).bind("scroll.myScroll", function() {});

Then unbind it:

"myScroll" is a namespace you chose.