Kmills94
1/2/2018 - 7:55 PM

AngularJs

//DIRECTIVE
.directive('infiniteScroll', function () {
    return {
        restrict: 'A',
        scope: { method: '&infiniteScroll' },
        link: function (scope, element, attrs) {
            var raw = element[0];

            element.bind('scroll', function () {
                if (Math.round(raw.scrollTop) + raw.offsetHeight >= raw.scrollHeight) {
                    scope.$emit('showMore');
                }
            });
        }
    }
});


//HTML
<div class="col-md-12" style="max-height: 650px; overflow-y: auto" infinite-scroll>

//CONTROLLER
scope.$on('showMore', function (event) {
    //Do stuff
    $scope.$apply();
});