I'm stucked with problem. I have a directive for infinite-scroll where I listen for scroll
event. The problem is that scroll event is only fired when I'm binding to $window
:
angular.element($window).bind('scroll', function () {
console.log('Gogo!'); //works!
});
element.bind('scroll', function () {
console.log('Gogo!'); //doesn't work... :(((
});
Directive is inside ng-view
I found this question, looks very similar to my problem - Binding to events in a directive which is inside a ng-view doesn't work
Anybody knows how to solve this? Thanks!
My directive:
directives.directive('scrolly', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var raw = element[0];
element.bind('scroll', function () {
if (raw.scrollTop + raw.offsetHeight > raw.scrollHeight) {
scope.$apply(attrs.scrolly);
}
});
}
};
});
My view:
<ul class="items-wrap" scrolly="showMore()">
<li class="item" ng-repeat="item in items">{{item.name}}</li>
</ul>