I am well-versed in detecting the end of a document while scrolling using plain JS. However, I am facing difficulty in implementing this functionality in AngularJS. I understand that I need to attach the scroll event to both the $window and $document. My question is: where should I implement this behavior? Should I use directives or services? If anyone can guide me on the correct way to implement this kind of detection in AngularJS, I would greatly appreciate it.