Answer the question
In order to leave comments, you need to log in
How to make pagination in angular?
I started to study angularJS, in the future I plan to transfer the project from php to angular .
I am doing this lesson.
Everything works fine, except for pagination, or rather, it is not there at all.
Example controller from the lesson:
yii2AngApp_film.controller('index', ['$scope', '$http', 'services',
function($scope,$http,services) {
$scope.message = 'Everyone come and see how good I look!';
services.getFilms().then(function(data){
$scope.films = data.data;
});
$scope.deleteFilm = function(filmID) {
if(confirm("Are you sure to delete film number: " + filmID)==true && filmID>0){
services.deleteFilm(filmID);
$route.reload();
}
};
}])
yii2AngApp_film.controller('index', ['$scope', '$http', 'services',
function($scope,$http,services) {
$scope.message = 'Everyone come and see how good I look!',
$scope.filteredFilms = [],
$scope.currentPage = 1,
$scope.numPerPage = 6,
$scope.maxSize = 3;
services.getFilms().then(function(data){
$scope.films = data.data;
});
$scope.deleteFilm = function(filmID) {
if(confirm("Are you sure to delete film number: " + filmID)==true && filmID>0){
services.deleteFilm(filmID);
$route.reload();
}
};
$scope.numPages = function () {
return Math.ceil($scope.films.length / $scope.numPerPage);
};
$scope.$watch('currentPage + numPerPage', function() {
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;
$scope.filteredFilms = $scope.films.slice(begin, end);
});
}])
<div ng-show="filteredFilms.length > 0">
<a class="btn btn-primary" href="#/film/create">
<i class="glyphicon glyphicon-plus"></i> Добавить
</a>
<table class="table table-striped table-hover">
<thead>
<th>Название</th>
<th>Режиссер</th>
<th>Описание</th>
<th>Год</th>
<th style="width:80px;">Действия </th>
</thead>
<tbody>
<tr ng-repeat="data in filteredFilms">
<td>{{data.title}}</td>
<td>{{data.director}}</td>
<td>{{data.storyline}}</td>
<td>{{data.year}}</td>
<td>
<a class="btn btn-primary btn-xs" href="#/film/update/{{data.id}}">
<i class="glyphicon glyphicon-pencil"></i>
</a>
<a class="btn btn-danger btn-xs" ng-click="deleteFilm(data.id)">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
</tr>
</tbody>
</table>
</div>
<div data-pagination="" data-num-pages="numPages()"
data-current-page="currentPage" data-max-size="maxSize"
data-boundary-links="true"></div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question