如何在angular-ui分页中更新我的总项目

时间:2014-09-23 09:21:31

标签: angularjs pagination angular-ui

当我呼叫服务和服务返回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个函数,但是我的分页它没有更新我很困惑

1 个答案:

答案 0 :(得分:0)

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);
 });
}

};