How to handle anchor hash linking in AngularJS

后端 未结 27 864
后悔当初
后悔当初 2020-11-22 12:22

Do any of you know how to nicely handle anchor hash linking in AngularJS?

I have the following markup for a simple FAQ-page



        
27条回答
  •  隐瞒了意图╮
    2020-11-22 13:09

    In my mind @slugslog had it, but I would change one thing. I would use replace instead so you don't have to set it back.

    $scope.scrollTo = function(id) {
        var old = $location.hash();
        $location.hash(id).replace();
        $anchorScroll();
    };
    

    Docs Search for "Replace method"

提交回复
热议问题