我正在嘗試使用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();
我有正確的格式,現在的URL,但$ anchorScroll( )沒有向下滾動到頁面。 –
我會說實話,我從來沒有使用過anchorscroll。 '$ location.hash()'輸出你期望的結果(第二個散列)? – charlietfl
是的,它會正確更新哈希值(當我指定路徑時),但除了反映更改的URL瀏覽器欄以外沒有任何反應。 –