2013-02-25 52 views
13

我正試圖在角度/引導站點上實現分頁。我有數據顯示每頁正確的#行,我有角度分頁顯示正確的頁數......但是,如果我能找到任何地方告訴我如何使用分頁來刷新我的數據頁面#被點擊...?! {{currentPage}}正在更新,但不知道如何讓它調用getPresentations來更新列表。角度分頁 - 更新數據onclick

<div> 
     {{noOfPages}} &nbsp; {{currentPage}} &nbsp; {{maxSize}} 
     <pagination num-pages="noOfPages" current-page="currentPage"></pagination> 
    </div> 

<script type="text/javascript"> 
    angular.module('app', ['ui', 'shared', 'ui.bootstrap']).controller('AppCtl', function ($scope, $http, $window) { 
     var mvc = $window.MVC; 
     $scope.noOfPages = 0; 
     $scope.currentPage = 1; 
     $scope.maxSize = 5; 

     $scope.getPresentations = function() { 
      $http.get(mvc.base + "API/Presentations?page=" + $scope.currentPage + "&itemsPerPage=10") 
       .success(function (result) { 
        $scope.presentations = result.Items; 
        $scope.noOfPages = result.TotalPages; 
        $scope.currentPage = result.Page; 
       }) 
       .error(function (result, status) { 
        $scope.newModal.errors = mvc.getApiErrors(status, result); 
       }); 
     }; 

     $scope.getPresentations(); 
    }); 
</script> 

回答

36

你有2種選擇:

  • $watch當前頁的屬性
  • 使用onSelectPage回調

這裏是$watch

$scope.$watch('currentPage', function(newPage){ 
    $scope.watchPage = newPage; 
    //or any other code here 
    }); 
相關頁面

這裏使用一個回調:

$scope.pageChanged = function(page) { 
    $scope.callbackPage = page; 
    $scope.watchPage = newPage; 
    }; 

使用,如:

<pagination on-select-page="pageChanged(page)" num-pages="noOfPages" current-page="currentPage"></pagination>  

最後的工作花掉顯示2種方法: http://plnkr.co/edit/UgOQo7?p=preview

+4

謝謝!我知道它不會太多......令我感到厭煩的是,他們沒有在文檔中包含這部分內容。 – NikZ 2013-02-26 15:22:29

+1

感謝您的回答!在「pageChanged」示例中,$ scope.watchPage = newPage的用途是什麼? – standingwave 2014-03-14 07:48:33

+1

我要瘋了,因爲在來到這裏之前我已經嘗試了這兩種方法,但都沒有工作:( – Dustin 2014-08-14 16:58:29

5

@ pkozlowski.opensource答案是正確的,除了最近版本的引導已經改變在選擇頁ng-change