I would like to do pagination like in this link How to use UI Bootstrap Pagination for a table, generated using ng-repeat
I have read the docs here https://angular-ui.github.io/bootstrap/#!#getting_started ng-model="pageNumber", but I don't know what is meant by 'This setting has an angular $watch listener applied to it', for example, ng-model has a $watch listener.
I am using components. What is meant by $watch listener and how do I use $watch inside a component. Is it even possible or is there a different way? checkout my plunker for all of the code. https://plnkr.co/edit/E2dKJx2PB1BXsE9hFkte?p=preview
booking-list.html
<ul
uib-pagination
ng-model="$ctrl.currentPage"
items-per-page="$ctrl.itemsPerPage"
total-items="$ctrl.bookings.length"
max-size="$ctrl.maxSize">
</ul>
<table>
...
<tr ng-repeat="booking in $ctrl.bookings">
...
</tr>
</tbody>
</table>
what should I do to make this work?
app.component('bookingList', {
templateUrl: 'booking-list.html',
controller: ['BookingSvc', function(BookingSvc) {
let self = this;
self.bookings = BookingSvc.query();
self.maxSize = 2;
self.currentPage = 1;
self.itemsPerPage = 2;
// what should I do to make this work?
/*$scope.$watch("currentPage", function() {
setPagingData(self.currentPage);
});
function setPagingData(page) {
let pagedData = self.bookings.slice(
(page - 1) * self.itemsPerPage,
page * self.itemsPerPage
);
self.pagedBookings = pagedData;
}*/
}]
});