Reputation: 97
I used button click to change the route to the next page. Angular JS retain the scroll position and doesn't scroll to the top of the ng-view. 1. Disabling $anchorScroll doesn't work 2. Using window scroll to doesn't work
$rootScope.on("$routeChangeSuccess", function(){
window.scrollTo(0,90);
})
However, to keep the fix header on iPad, the following window scroll works.
$(document).on('blur', 'input, textarea', function() {
setTimeout(function() {
window.scrollTo(document.body.scrollLeft,document.body.scrollTop);
}, 0);
});
Any suggestions? How to clear the stored scroll positions by angualar js view?
Upvotes: 2
Views: 8143
Reputation: 3408
Minor update to @Rafael's answer.
Since Angular 1.3.14 you can use simpler syntax to enable autoscroll to the top when switching views with ngView
:
<div ngView autoscroll></div>
Upvotes: 2
Reputation: 6709
What you want is not disable anchorscroll, but enable it. You can achieve what you want using the following code:
<div data-ng-view data-autoscroll="true"></div>
or:
<div data-ng-view data-autoscroll></div>
as pointed in the AngularJS docs.
Upvotes: 6
Reputation: 7292
Have you tried setting autoscroll to false on your ng-view element?
<div data-ng-view data-autoscroll="false"></div>
Upvotes: 1