I am using $anchorScroll
to scroll to page top where the html element has ID #brand
.
<body>
<header id="brand">
<!--Content-->
</header>
</body>
AngularJS code:
$location.hash("brand");
$anchorScroll();
However, after $anchorScroll
runs, the page url becomes http://localhost:8080/##brand
, which means ##brand
is appended to the original url. How can I keep the original url when using $anchorScroll
? Thanks in advance!
Using $anchorScroll in its explicit form seems to work, at least when html5mode is on.
(do not call $location.hash())
$anchorScroll('brand');
There's no way to prevent the hash from being added to the URL; you are explicitly doing just that by invoking $location.hash("brand");
. You can, however, remove it by invoking $location.hash(null);
after anchorScroll.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With