As I embark on my first project using Angular 1.5.x, things have been going smoothly so far.
However, I recently encountered a simple challenge of logging window position/event on scroll. Despite trying various methods like directives, event binding, and even jQuery, nothing seems to be showing up in the console.
In vanilla JavaScript, I would typically use a simple code snippet like this:
window.onscroll = function (e) {
console.log(e);
}
Attempting to adapt this to Angular in my controller like so:
angular.element($window).on('scroll', function (e) {
console.log(e);
});
Results in no output. While changing the event to click or resize triggers a response, scrolling does not. This has been quite frustrating.
Even after trying a directive, the result remains the same – nothing.
It seems that Angular might be removing or overriding the scroll event in some way. I'm hopeful that there is a straightforward solution or another method I should be using.
Thank you for taking the time to address my question.
Any help or advice would be greatly appreciated.