第一 我使用了ng表格分页器模板
我无法使用我的自定义功能,例如ng-click =' first()'而不是ng-click =" params.page(page.number)"
然后在其范围内调用参数。
任何人都可以帮助我。感谢。
答案 0 :(得分:1)
绑定到ngTable的自定义分页模板会创建一个新范围,因为只有使用params.page(1)等参数定义的函数才能工作。 因此,不是将自定义分页模板绑定到ngTable,而是可以使用一组单独的控件来提供分页功能。
请参阅plunkr:http://plnkr.co/edit/dZf4UkRbhQd2Jixi9f39?p=preview
的index.html
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@*" data-semver="1.2.0-rc3-nonmin" src="http://code.angularjs.org/1.2.0-rc.3/angular.js"></script>
<script data-require="ng-table@*" data-semver="0.3.0" src="http://bazalt-cms.com/assets/ng-table/0.3.0/ng-table.js"></script>
<link data-require="ng-table@*" data-semver="0.3.0" rel="stylesheet" href="http://bazalt-cms.com/assets/ng-table/0.3.0/ng-table.css" />
<link data-require="bootstrap-css@*" data-semver="3.0.0" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app="main" ng-controller="DemoCtrl">
<table ng-table="tableParams" class="table">
<tr ng-repeat="user in $data">
<td data-title="'Name'">
{{user.name}}
</td>
<td data-title="'Age'">
{{user.age}}
</td>
</tr>
</table>
<p><strong>Page:</strong> {{ tableParams.page() }}</p>
<button class="btn btn-default" ng-click="previous()">Previous</button>
<button class="btn btn-default" ng-click="next()">Next</button>
<button class="btn btn-default" ng-click="info()">Info</button>
</body>
</html>
的script.js
var app = angular.module('main', ['ngTable']).
controller('DemoCtrl', function($scope, ngTableParams) {
var data = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];
var count=1;
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 5 , // count per page
}, {
counts: [], // hide page counts control
total: 1, // value less than count hide pagination
getData: function($defer, params) {
$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
this.current=params.count();
}
});
$scope.next=function(){
console.log("next called");
count++;
$scope.tableParams.page(count);
};
$scope.previous=function(){
console.log("previous called");
if(count>1)
count--;
$scope.tableParams.page(count);
}
$scope.info=function(){
console.log("info called");
console.log("page: "+(($scope.tableParams.page() - 1) * $scope.tableParams.count())+"to"+($scope.tableParams.page() * $scope.tableParams.count()));
}
});
这里我已经在控制器中定义了自定义函数,并使用$ scope.tableParams.page(count)来分页到特定页面。