Rothschild Rothschild - 1 year ago 164
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download