2014-07-05 28 views
8

我正在嘗試使用AngularJS $anchorScroll$location.hash。但是,當我設置散列時,AngularJS在它之後添加了一個正斜槓。AngularJS提出斜槓/散列標記後

例如,網址是:http://localhost:13060/Dashboard。當我不包含AngularJS庫時,我可以點擊鏈接#contact,然後轉到http://localhost:13060/Dashboard#contact

但是,當我包含AngularJS並單擊鏈接時,它會去http://localhost:13060/Dashboard#/contact阻止$ anchorScroll工作。

編輯$ anchorScroll不工作

起始URL是http://localhost:13060/Category。 當我添加一個類別時,它應該去http://localhost:13060/Category#/#id(其中id是新的id)並向下滾動頁面。 URL正確更新,但$ anchorScroll不滾動。

//jump to new category 
$location.path(""); 
$location.hash(cat.ID); 
$anchorScroll(); 

回答

5

除非使用html5mode,其從角路由消除了散列,你將有2個散列,一個用於角路由和其它用於錨。

http://localhost:13060/Dashboard#/#contact

假如你想知道的路由路徑設置爲/profiles和錨是該視圖中的URL看起來像:

http://localhost:13060/Dashboard#/profiles#contact

+0

我有正確的格式,現在的URL,但$ anchorScroll( )沒有向下滾動到頁面。 –

+0

我會說實話,我從來沒有使用過anchorscroll。 '$ location.hash()'輸出你期望的結果(第二個散列)? – charlietfl

+0

是的,它會正確更新哈希值(當我指定路徑時),但除了反映更改的URL瀏覽器欄以外沒有任何反應。 –