简体   繁体   English

AngularJs动态加载

[英]AngularJs Dynamic Loading

Hi This is my AngularJs One time loads pagination ... Can any one please tell me how can i implement lazy loading with this (That is I need to call the service every time for each page) 嗨,这是我的AngularJs。一次加载分页...谁能告诉我如何实现延迟加载(也就是说,我需要每次为每个页面调用服务)

//get the list and injects to the template
        DWHDataExtract.list().then(function(response){

            DWHDataExtract.loaded = response.data;
            $scope.dwhDataExtractDetails = DWHDataExtract.loaded;
            $scope.stParams.reload();

        });
        // parameters declared inside the scope for row count and pagination view
        $scope.stParams = new ngTableParams({

                page: 1, // show first page
                count: 10 // count per page
            },
            {
                counts: [10, 25, 50, 100],
                total: $scope.dwhDataExtractDetails.length,

                getData: function($defer, params) {
                    //this criteria is for search filters
                    var searchOptions = params.filter();
                    var filteredList = searchOptions ? $filter('filter')($scope.dwhDataExtractDetails, searchOptions) : $scope.dwhDataExtractDetails;
                    var orderedData = params.sorting() ? $filter('orderBy')(filteredList, params.orderBy()) : filteredList;

                    params.total(orderedData.length); // set total for recalc pagination
                    if(params.total() < (params.page() -1) * params.count()){
                        // auto reset to first page if the current page is Out Of Bounds following a recent filter
                        params.page(1);
                    }

                    $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                }
            });

This could be put into a put into the controller so that it runs everytime a new controller is created. 可以将其放入控制器中,以便每次创建新控制器时都可以运行。

angular.module('App') .controller('controller', ["$scope", function($scope){ angular.module('App').controller('controller',[“ $ scope”,function($ scope){

//PUT YOUR CODE HERE. //在此处输入您的代码。 }]); }]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM