AngularJS Paging with $location.path but no ngView reload
From this blog post:
by default all location changes go through the routing process, which updates the angular view.
There’s a simple way to short-circuit this, however. Angular watches for a location change (whether it’s accomplished through typing in the location bar, clicking a link or setting the location through
$location.path()
). When it senses this change, it broadcasts an event,$locationChangeSuccess
, and begins the routing process. What we do is capture the event and reset the route to what it was previously.
function MyCtrl($route, $scope) {
var lastRoute = $route.current;
$scope.$on('$locationChangeSuccess', function(event) {
$route.current = lastRoute;
});
}
Instead of updating the path, just update query param with a page number.
set your route to ignore query param changes:
....
$routeProvider.when('/foo', {..., reloadOnSearch: false})
....
and in your app update $location
with:
...
$location.search('page', pageNumber);
...