AngularJS 창 슬라이더를 드래그하여 추가 로드하기

1598 단어



코드 예:

hubListComponents.controller('unitarySearchCtrl', ['$scope', '$window', '$document', '$interval', '$routeParams', '$resource', function ($scope, $window, $document, $interval, $routeParams, $resource) {

        var Components = $resource('rest/components/:componentName',{
            componentName:"@componentName"
        });        

        $scope.allComponents = [];
        $scope.components = [];
        $scope.searchText=$routeParams.componentName;

        var start = 0,
            increment = 4,
            end = increment;

        Components.query({componentName:$routeParams.componentName},function(data){
            $scope.allComponents = data;

            $scope.components = $scope.allComponents.slice(start, end);

            start += increment;
            end += increment;

            var promise = $interval(function () {
                if (angular.element($window).height() >= angular.element($document).height()) {
                    $scope.loadMore();
                } else {
                    $interval.cancel(promise);
                }
            }, 0);
        });

        $scope.loadMore = function () {
            var slicedComponents = $scope.allComponents.slice(start, end);
            for (var i = 0; i < slicedComponents.length; i++) {
                $scope.components.push(slicedComponents[i]);
            }
            start += increment;
            end += increment;
        };

    }]);

좋은 웹페이지 즐겨찾기