Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS提出了正斜杠/后散列标记_Angularjs_Hashtag_Anchor Scroll - Fatal编程技术网

AngularJS提出了正斜杠/后散列标记

AngularJS提出了正斜杠/后散列标记,angularjs,hashtag,anchor-scroll,Angularjs,Hashtag,Anchor Scroll,我正在尝试将AngularJS与$location.hash一起使用。但是,当我设置散列时,AngularJS会在其后面添加一个正斜杠,/ 例如,url是:http://localhost:13060/Dashboard。当我没有包含AngularJS库时,我可以单击链接,#contact,然后转到http://localhost:13060/Dashboard#contact 但是当我加入AngularJS并点击链接时,它会转到http://localhost:13060/Dashboard#

我正在尝试将AngularJS与
$location.hash
一起使用。但是,当我设置散列时,AngularJS会在其后面添加一个正斜杠,/

例如,url是:
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();

除非您使用HTML5模式(从角度路由中删除散列),否则您将有2个散列,一个用于角度路由,另一个用于锚定

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

假设您将路由路径设置为
/profiles
,并且锚点位于该视图中,则url如下所示:


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

我现在已经正确格式化了URL,但是$anchorScroll()没有向下滚动到页面。老实说,我从来没有使用过anchorScroll。
$location.hash()
是否输出您期望的内容(第二个散列)?是的,它正确地更新了散列(当我指定路径时),但是除了反映更改的URL浏览器栏外,什么也没有发生。我发现了问题。我在承诺的结果中有$anchorScroll(即categories.then),我更改了$scope。在$scope更改传播到视图之前,我调用了hash函数,因此hash不在那里,所以它不会滚动。我在$anchorScroll中添加了一个超时,从而修复了它。@jth_92很高兴看到一个JSFIDLE或其他东西,我有同样的问题,但我不知道您添加$location.path(“”)的确切位置$位置散列(类别ID);