【问题标题】:How to update my total-items in angular-ui pagination如何在 angular-ui 分页中更新我的总项目
【发布时间】:2014-09-23 19:05:12
【问题描述】:

当我调用服务和服务返回 data.length 时,我想更改分页中的总项目

当我在输入模型中点击搜索时调用的服务

在我的搜索 html 中

<form ng-submit="submit(key1.index1)" ng-controller="searchController">
  <input type="text"
         class="form-control"
         id="inputKey1"
         placeholder="Enter Key 1"
         ng-model="key1.index1">
</form>

在我的索引 html 中

<div ng-controller="searchController" >
  <pagination total-items="totalItems"
              ng-model="currentPage"
              max-size="maxSize"
              class="pagination-sm"
              boundary-links="true"
              ng-change="pageChanged()"
              items-per-page="items_per_page">
  </pagination>
</div>

在我的控制器中

app.controller('searchController', function ($scope,Service) {
  $scope.totalItems = 0;
  $scope.submit = function (index1) {
    Service.getID("test", index1).then(function (listDocc) {
      $scope.totalItems = listDocc.length;  
      console.log( $scope.totalItems);
    });
  }
};

我在函数中的 $scope.roralItems 中有 20 个,但我的分页没有更新我很困惑

【问题讨论】:

    标签: angularjs pagination angular-ui


    【解决方案1】:
    app.controller('searchController', function ($scope,Service) {
    $scope.totalItems = 0;
    $scope.submit = function (index1) {
    Service.getID("test", index1).then(function (listDocc) {
      $scope.totalItems = listDocc.length;  
     // try this 
      if(!$scope.$$phase){$scope.$apply();}
      console.log( $scope.totalItems);
     });
    }
    

    };

    【讨论】:

    • 因此,您需要检查 $digest 是否正在进行中,如果没有,则使用 $scope.$apply();为此,您需要这样做 if (!scope.$$phase ) { $scope.$apply() }
    • 如何检查 $digest 因为我从不在我的控制器中使用 $digest。 p.s.谢谢
    • chk 已编辑答案...!!! $scope.$$phase 是一个由 angularjs 维护的标志,用于检查 $digest 是否正在进行
    猜你喜欢
    • 2018-03-21
    • 1970-01-01
    • 2014-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-12
    • 1970-01-01
    相关资源
    最近更新 更多