2017-08-18 10 views
0

$ httpから返されるデータをページングできません。ページは1ページしか表示されません。私はこのplunkerに従っていますが、なぜそれがページネーションをしていないのかは分かりません。Angularjsページネーションのみ表示1

これはこれは、response.data

{"id":"1","name":"name 1","description":"description 1","field3":"field3 1","field4":"field4 1","field5 ":"field5 1"}, 
{"id":"2","name":"name 2","description":"description 1","field3":"field3 2","field4":"field4 2","field5 ":"field5 2"}, 
{"id":"3","name":"name 3","description":"description 1","field3":"field3 3","field4":"field4 3","field5 ":"field5 3"}, 
{"id":"4","name":"name 4","description":"description 1","field3":"field3 4","field4":"field4 4","field5 ":"field5 4"}, 
{"id":"5","name":"name 5","description":"description 1","field3":"field3 5","field4":"field4 5","field5 ":"field5 5"}, 
{"id":"6","name":"name 6","description":"description 1","field3":"field3 6","field4":"field4 6","field5 ":"field5 6"}, 
{"id":"7","name":"name 7","description":"description 1","field3":"field3 7","field4":"field4 7","field5 ":"field5 7"}, 
{"id":"8","name":"name 8","description":"description 1","field3":"field3 8","field4":"field4 8","field5 ":"field5 8"}, 
{"id":"9","name":"name 9","description":"description 1","field3":"field3 9","field4":"field4 9","field5 ":"field5 9"}, 
{"id":"10","name":"name 10","description":"description 1","field3":"field3 10","field4":"field4 10","field5 ":"field5 10"} 

の内側にある

$scope.currentPage = 1; 
$scope.numPerPage = 2; 
$scope.maxSize = 5; 

$scope.makeTodos = function() { 
    $scope.todos = response.data; //return of $http 
} 
$scope.makeTodos(); 

$scope.$watch('currentPage + numPerPage', function() { 
    var begin = (($scope.currentPage - 1) * $scope.numPerPage); 
    var end = begin + $scope.numPerPage; 

    $scope.names = $scope.todos.slice(begin, end); 
    console.log($scope.todos.slice(begin, end)); 
}); 

私のスクリプトでEDITED

これは

<body ng-controller="TodoController"> 
    <h1>Todos</h1> 
    <h4>{{todos.length}} total</h4> 
    <ul ng-repeat="x in names"> 
     <li>{{x.id}}</li> 
     <li>{{x.name}}</li> 
     <li>{{x.description}}</li> 
     <li>{{x.field3}}</li> 
     <li>{{x.field4}}</li> 
     <li>{{x.field5}}</li> 
    </ul> 
    <pagination 
     ng-model="currentPage" 
     total-items="names.length" 
     max-size="maxSize" 
     boundary-links="true"> 
    </pagination> 
    </body> 
私のHTMLですあなたのページ付け部品で
+0

更新され

<pagination ng-model="currentPage" total-items="names.length" items-per-page='numPerPage' max-size="maxSize" boundary-links="true"> </pagination> 

HTMLページにコードを表示することができますようにそれに応じて

あなたの最終的なコードがされる動作しますitems-per-page='numPerPage'属性を追加 – Akashii

+0

'ui.bootstrap'を依存関係として追加しましたか?あなたのHTMLコードに 'ui-bootstrap'を含めましたか? –

+0

@SudhansuChoudharyはい私はui-bootstrapを追加しました –

答えて

2

だけで、あなたのページングは​​ここでは例としてPlunker

+1

ありがとうございました! –

関連する問題