单击链接时,Angularjs分页数据不会刷新

时间:2018-01-04 11:28:12

标签: angularjs http pagination

我有一个分页工厂,我没有写,我只是使用它,它传递$ scope和一个字符串,表示http动作的字符串。  它适用于GET个请求但是我现在正在尝试在POST请求上实现它,并且由于某种原因它无法正常工作。使用适量的按钮加载分页栏。例如,我有一千条记录它每页加载100个按钮10条记录但是当点击按钮时数据是静态的,它不会更新。

分页工厂:

angular.module('customers')
       .factory('PaginationFactory', PaginationFactory);

function PaginationFactory($scope, action) {

    $scope.filteredPages = [];
    $scope.currentPage = 1;
    $scope.numPerPage = 10;
    $scope.maxSize = 15;

    $scope.makePages = function () {
         $scope.search_customers = [];

         angular.forEach($scope.get_list, function (item) {
             //Push the items into the list...
             if (callerAction == 'search_customers') {
                 $scope.search_customers.push(item);
              }
    });
};

$scope.$watch('currentPage + numPerPage', function () {

    var begin = (($scope.currentPage - 1) * $scope.numPerPage)
    end = begin + $scope.numPerPage;

    if (callerAction == 'search_customers') {
        var pages = $scope.filteredPages = $scope.search_customers.slice(begin, end);
    return pages;
});
$scope.makePages();
}

HTML:

 <ul uib-pagination
     total-items="search_customers.length"
     ng-model="currentPage"
     max-size="maxSize"
     boundary-link-numbers="true"
     rotate="false">
 </ul>

发布请求:

 $scope.searchCustomers = function() {
    $scope.status = $scope.selected.charAt(0);
    $http.post(API_URL+"v1/customers/search", $scope.searchData)
        .then(function (response){
            var action = 'search_customers';
            $scope.get_list = response.data;
           console.log($scope)
            new PaginationFactory($scope, action);
        }, function (response) {
            console.log("no data");
        });

如果有人可以提供帮助,我们将不胜感激。谢谢。

0 个答案:

没有答案
相关问题