我有一个属性:$scope.Users.length,根据它,我的应用程序显示分页编号。虽然属性更改,但分页不更改。我想添加$scope.$watch来处理它,我怎么做呢?
分页属性:
$scope.totalItems = $scope.Users.length;
$scope.currentPage = 1;
$scope.itemsPerPage = 3;
$scope.maxSize = (($scope.Users.length / 3) + 1) ; //Number of pager buttons to showhtml中的分页:
<div>
<pagination total-items="totalItems" ng-model="currentPage" max-size="maxSize" class="pagination-md" boundary-links="true" rotate="false" num-pages="numPages" ng-click="pageChanged(user)" items-per-page="itemsPerPage"></pagination>
</div>发布于 2015-09-23 18:14:27
这样做的方法是,每次向页面添加新数据时都要对$watch进行$scope.totalitems。
$watch函数(放在add data函数中):
$scope.$watch('totalItems', function(newValue, oldValue) {
$scope.pageChange($scope.Users.length);
});将更改$scope.totalitems的函数,它负责页面的数量:
$scope.pageChange = function(pageNo) {
$scope.totalItems = pageNo;
};https://stackoverflow.com/questions/32744533
复制相似问题