Answer the question
In order to leave comments, you need to log in
AngularJS, how to return to the top of the page during pagination?
Structure
<body>
<header>...</header>
<ng-view></ng-view>
<footer></footer>
</body>
Answer the question
In order to leave comments, you need to log in
In the main controller itself, listen for page URL changes and scroll to the top:
$rootScope.$on('$routeChangeSuccess', function(e, current, previous) {
window.scrollTo(0, 0);
});
$routeProvider
.when('/:pageNumber?', {
templateUrl: 'partials/home.html',
controller: 'HomeCtrl'
})
watchesStore.controller('WatchesStoreController', function($routeParams, paginationService) {
var pageNumber = $routeParams.pageNumber || 1;
pageNumber = parseInt(page, 10);
var paginationId = 'watchesStore'; // setCurrentPage требует instanceId — айдишку экземпляра пагинатора, чтобы знать, какой блок, собственно, пагинировать
paginationService.setCurrentPage(paginationId, pageNumber);
});
$routeProvider
.when('/:watchId', {
templateUrl: 'partials/watch-detail.html',
controller: 'WatchDetailCtrl'
})
watchesStore.controller('WatchesStoreController', function($location, paginationService) {
var params = $location.search();
var pageNumber = params.page || 1;
pageNumber = parseInt(page, 10);
...
});
As far as I remember, there is such a construction:
DOCS<ng-view autoscroll></ng-view>
I use this schema
watchesStore.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: false
})
$routeProvider.
when('/', {
templateUrl: 'partials/home.html',
controller: 'HomeCtrl'
}).
when('/service', {
templateUrl: 'partials/service.html',
controller: 'ServiceCtrl'
}).
when('/contacts', {
templateUrl: 'partials/contacts.html',
controller: 'ContactsCtrl'
}).
when('/:watchId', {
templateUrl: 'partials/watch-detail.html',
controller: 'WatchDetailCtrl'
}).
otherwise({
redirectTo: '/'
});
}
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question