Reputation: 6850
I want to write a paginated
directive which works just like ng-repeat
but preprocessing the iterated collection first (for paging). I thought I could do something like:
<tr paginated="item for item in list" page="3" per-page="10">
<td>[[item.foo]]</td>
<td>[[item.bar]]</td>
</tr>
I want to implement this by reusing ng-repeat
somehow, but the few vague tries I gave to it didn't work. How could I do that?
This is the best I came up with (note it's not even exactly the same):
app.directive('paginated', function() {
return {
replace: true,
transclude: true,
scope: {
data: '=',
perPage: '@',
},
template:
'<div ng-repeat="item for item in l"><div ng-transclude></div>',
link: function(scope, elem, attrs, ngRepeat) {
scope.l = data;
// do stuff with scope.l
},
}
});
Upvotes: 3
Views: 930
Reputation: 28750
You can use a filter to do pagination, here's another stackoverflow question where you can see how it's implemented: Pagination on a list using ng-repeat
Upvotes: 2