参数变量出现ngTable指令问题

ngTable directive issue with params variable

本文关键字:指令 问题 ngTable 变量 参数      更新时间:2023-09-26

我正在为网格使用ngTable指令。我需要通过控制器设置页数。假设我需要将页面大小设置为50。我该怎么做?如何从控制器访问params变量?

我试过如下。但它在TypeError: Cannot read property 'count' of undefined 处抛出异常

$scope.params.count(50);

Html

<button type="button" ng-class="{'active':params.count() == 50}" ng-click="params.count(50)" class="btn btn-default">50</button>

js

$scope.tableParams = new ngTableParams({
        page: 1,            // show first page
        count: 10           // count per page
    }, {
        total: data.length, // length of data
        getData: function($defer, params) {
            $defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
        }
    });

count是一个属性,您的作用域中没有params变量,只有tableParams。。。tableParams.count看起来更好

 $scope.tableParams.count(50);