2016-06-28 99 views
2

我使用$anchorScroll滚动到页面顶部,其中html元素的ID为#brand

<body> 
    <header id="brand"> 
     <!--Content--> 
    </header> 
</body> 

AngularJS代码:

$location.hash("brand"); 
$anchorScroll(); 

然而,经过$anchorScroll运行时,该页面的网址将成为http://localhost:8080/##brand,这意味着##brand被附加到原始URL。如何在使用$anchorScroll时保留原始网址?提前致谢!

回答

4

以明确的形式使用$ anchorScroll似乎工作,至少在html5mode打开时。

(do not call $location.hash()) 
$anchorScroll('brand'); 
+0

谢谢。有用! – NMSL

+0

谢谢!为我节省了时间。 – CENT1PEDE

0

没有办法阻止散列被添加到URL;你明确地通过调用$location.hash("brand");来做到这一点。但是,您可以通过在anchorScroll后调用$location.hash(null);来删除它。