AngularJS锚点第二次不起作用 [英] AngularJS Anchor click not working second time

查看:81
本文介绍了AngularJS锚点第二次不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的演示

app.run(function($rootScope, $location, $anchorScroll) {
      //when the route is changed scroll to the proper element.
      $rootScope.$on('$routeChangeSuccess', function(newRoute, oldRoute) {
        console.log("called routeChangeSuccess");
        if ($location.hash()) $anchorScroll();
      });
    });

  1. 点击转到一个结尾,它将导航到具有ID的div
  2. 第二次单击相同的链接将不会执行任何操作
  1. Click on go to end of one it will navigate to the div with the id
  2. Second time click on the same link it wont do anything

我做错了什么?还是与角度有关?

What i am doing wrong? or is this something to do with angular ?

注意:hack的目的是使用click事件,这应该在寻找直接解决方案的时候起作用

Note: hack for this would be to use click event and this should work am looking for direct solutions

使用角度和路线版本1.5.5

using angular and route version 1.5.5

*添加了赏金

推荐答案

我检查了您的plunkr,我发现在指定锚标记时您未指定路线,因此'$ routeChangeSuccess当我将特定行更改为此时,'不会被触发

I checked your plunkr, I noticed that you were not specifying the route, when giving the anchor tag, thus the '$routeChangeSuccess' isn't triggered, when I change the particular line to this

<a href="/one/#one"> go to end of one </a>

我的锚定滚动条正常工作.

I anchor scroll works properly.

解决方案: Plunkr

请注意HTML5模式在路由方面的挑战,

Please note the challenges of HTML5 mode in routing, here, if you have not already taken this into account.

这篇关于AngularJS锚点第二次不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆