-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Pagination example doesn't change the page URL #620
Comments
@tobireif I'm not sure I understand you correctly: would you expect a pagination directive to change the URL of an AngularJS application? As it definitively wasn't designed for this, it is a general-purpose pagination that can be used with different result sets and execute different actions when a given item in a pagination is selected. Could you be more precise? |
Yes I would expect the directive to change the URL each time the displayed content of the page changes (at least as an option to set eg when the changing content is a major part of the page content), but it's OK if this one doesn't - I could add that functionality myself. Feel free to close. |
+1 |
Hi @ tobireif can you provide an example how did u made paginations URL change? |
@tobireif can you provide an example how did u made paginations URL change? |
+1 Although this can be implemented easily it would be great to have it as an option. <pagination items-per-page="15" max-size="5" total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()"></pagination> .controller('SamplesIndexCtrl', ['$scope', '$location', '$http', '$routeParams',
function($scope, $location, $http, $routeParams) {
$scope.search = function() {
$http.get('/search', { page: $routeParams.page }).then(function(response) {
$scope.samples = response.data.samples;
});
};
$scope.search();
$scope.pageChanged = function() {
$location.url('/samples?page=' + $scope.currentPage);
};
}
); |
@nicolasgarnil Are you sure your solution works? I figured out exactly the same solution, but every time I envoke
I believe the is because the pagination directive sets currentPage to 1 by default. Is it possible to turn this off? |
@tsikov Exact same issue with me! |
Guys, problem solved! For changing the url, you need to listen the ng-change pagination directive and call $location.search({pag: $scope.currentPage}); My problem: My workaround was to set $scope.currentPage into my list items success function. So, I didn't need to set the currentPage into the controller initialization. |
@diogenesgg currently having this issue at present would you be able to display an example of how you got around this? |
@diogenesgg never mind managed to get it working. I wrap my pagination in a div with an ng-if to only load pagination once my array loads like so
This causes my ng-change not to fire twice as by the time the pagination is loaded my model item page has a value, hope this helps someone else. |
here is my clumsy code:
It supports browser's back/forward. |
Thanks KieranDotCo, It work for me. |
hi KieranDotCo, Thanks :) its for me |
With ui-router, using $stateParams instead of $routeParams |
When I go to http://angular-ui.github.io/bootstrap/#/pagination and open the Plunkr example, then view the content of the frame (in order to view the demo page itself), the URL of the page (eg http://run.plnkr.co/sfpGiAuFnlMXxoMJ/ ) doesn't get updated with each pagination step.
The text was updated successfully, but these errors were encountered: