1

I want to bind a page scroll event in my angular directive. I am trying the following code snippet. But it seems the event won't get fired:

angular.element($window).bind("scroll", function(e) {
    console.log('page scrolled');
});

I need help, how to achieve this?

2
  • Can you make sure that you've injected $window with your controller? also you can check with this existing plunker solution. Commented Sep 21, 2017 at 12:34
  • This seems to work as expected: plnkr.co/edit/VFOo1Beg7zpL0VCWWQRi?p=preview Commented Sep 21, 2017 at 13:03

1 Answer 1

0

Instead of $window, you may inject $document wrapper for the browser's window.document (see the doc) and use

$document.bind('scroll', function(event) {
  console.log('page scrolled');
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.