I am trying to scroll to an element on the page after I \'show\' it. I.E. i have a very long list of users and I display them as a list. Each element has an edit icon you can
Angulars routing seems to pick up the change, which in my case is bad because the scrollTo reroutes me to back to the main admin page.
Scrolling and then resetting the $location.hash() so angular does not perceive a change in url seems to work.
$scope.scrollTo = function (id) {
var old = $location.hash();
$location.hash(id);
$anchorScroll();
$location.hash(old);
}
Edit:
As mentioned in a comment by @theunexpected1, since 1.4.0
, Angular's $anchorScroll
allows you to directly pass the id as a parameter without the need to update the url with the hash:
$scope.scrollTo = function(id) {
// Pass the 'id' as the parameter here, the page will scroll
// to the correct place and the URL will remain intact.
$anchorScroll(id);
}