Reputation: 639
i'm using angularjs WITHOUT jquery, and trying to create scroll event listener.
tried this approach:
$rootScope.$watch(function() {
return $window.scrollY;
}, function(n,o) {
console.log('scroll');
});
but it dosen't work..
I managed to achieve this goal using this technique to create resize listener:
$rootScope.$watch(function() { // Listens to window size change
return $window.innerWidth;
}, function(n, o) {
console.log('resize');
});
is there a proper way to create pure angularjs scroll listener?
Upvotes: 4
Views: 6761
Reputation: 74
Yes. your correct AngularJs provide $anchorScroll to scroll across the page but not that much effective. You can either go top or bottom like this. If you want scroll at particular position across vertical or horizontal $anchorScroll doesn't have that option. You have to go for normal javascript even for animation also. If you would like to explore more in Angular Scroll please have a look at this answer. Grate!!
Upvotes: 0
Reputation: 639
creating scroll event listener, 'The Angular Way', is actually very simple, using $window:
$window.onscroll = function() {
console.log('scroll');
};
Upvotes: 5