8

我正在尝试将 AngularJS$anchorScroll$location.hash. 但是,当我设置哈希时,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();
4

1 回答 1

6

除非您使用 html5mode 从角度​​路由中删除散列,否则您将拥有 2 个散列,一个用于角度路由,另一个用于锚点。

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

假设您将路由路径设置为/profiles并且锚点位于该视图中,则 url 看起来像:

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

于 2014-07-05T23:49:14.220 回答