【问题标题】:AngularJS: $watchAngularJS:$手表
【发布时间】:2015-12-21 01:32:06
【问题描述】:

我有这个属性: $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 show

html中的分页:

<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>

【问题讨论】:

    标签: angularjs pagination scope watch


    【解决方案1】:

    这样做的方法是每次向页面添加新数据时$watch $scope.totalitems。

    $watch 函数(放在添加数据函数中):

    $scope.$watch('totalItems', function(newValue, oldValue) {
            $scope.pageChange($scope.Users.length);
        });
    

    改变负责页面数量的$scope.totalitems的函数:

    $scope.pageChange = function(pageNo) {
            $scope.totalItems = pageNo;
        };
    

    【讨论】:

      猜你喜欢
      • 2014-01-06
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-09
      • 2017-03-22
      • 1970-01-01
      相关资源
      最近更新 更多