Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9254549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:29:53+00:00 2026-06-18T11:29:53+00:00

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

  • 0

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

I have the following markup for a simple FAQ-page

<a href="#faq-1">Question 1</a>
<a href="#faq-2">Question 2</a>
<a href="#faq-3">Question 3</a>

<h3 id="faq-1">Question 1</h3>
<h3 id="faq-2">Question 2</h3>
<h3 id="fa1-3">Question 3</h3>

When clicking on any of the above links AngularJS intercepts and routes me to a completely different page (in my case, a 404-page as there are no routes matching the links.)

My first thought was to create a route matching “/faq/:chapter” and in the corresponding controller check $routeParams.chapter after a matching element and then use jQuery to scroll down to it.

But then AngularJS shits on me again and just scrolls to the top of the page anyway.

So, anyone here done anything similar in the past and knows a good solution to it?

Edit: Switching to html5Mode should solve my problems but we kinda have to support IE8+ anyway so I fear it’s not an accepted solution :/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:29:55+00:00Added an answer on June 18, 2026 at 11:29 am

    You’re looking for $anchorScroll().

    Here’s the (crappy) documentation.

    And here’s the source.

    Basically you just inject it and call it in your controller, and it will scroll you to any element with the id found in $location.hash()

    app.controller('TestCtrl', function($scope, $location, $anchorScroll) {
       $scope.scrollTo = function(id) {
          $location.hash(id);
          $anchorScroll();
       }
    });
    
    <a ng-click="scrollTo('foo')">Foo</a>
    
    <div id="foo">Here you are</div>
    

    Here is a plunker to demonstrate

    EDIT: to use this with routing

    Set up your angular routing as usual, then just add the following code.

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

    and your link would look like this:

    <a href="#/test?scrollTo=foo">Test/Foo</a>
    

    Here is a Plunker demonstrating scrolling with routing and $anchorScroll

    And even simpler:

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

    and your link would look like this:

    <a href="#/test#foo">Test/Foo</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does any know if the following is the expected behaviors in terms of what
I know the answer to this is going to be simple, but I have
Do you know any good tools for nicely formatting messy php code? Preferably a
Does any know of a good calendar (not datepicker, but a BIG browsable calendar)
Any one know how to apply a css propert to the a tag, but
Does any body know how to set different select statement for the same cursor?
Does any one know why the location indicator stay on for certain bundle identifer
does any one know how to make the slide to left effect like in
Do you know any way for safe copy cut operation in Android? I want
Do you know any library that will help doing that? I would write a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.