AngularJS window scroll event does not fire

I know that there are some similar questions regarding this problem, however, none of the solutions could help me.

I am using AngularJS and want to detect a scroll event. I tried many versions on how to get the event, but it fires on first boot, and then never again.

My last code I tried was as follows:

$($window).on('scroll', alert('scrolled')); 

But I also tried this:

and much more, but nothing works.

Can someone tell me what I am doing wrong?

Update: I tried the directive stuff, this works fine with safari, but not chrome. What's happening?

Update2: it works with the Chrome mobile view when using the shift key. Are there any restrictions on the chrome apple trackpad? WTF?

+6
source share
2 answers

I would just use

 $(window).scroll(function () { alert('scrolled') }) 

OR you can use

 angular.element($window).bind("scroll", function(e) { alert('scrolled') }) 
+5
source

there is no need for angular.element () to enter $ window to your controller

$window.onscroll = function(){ console.log('window was scrolled!'); };

+1
source

All Articles