0

I'm just starting angular and am able to display the homepage via the url: http://localhost:8002/app/#/home

Now, I want to use a name tag, to go to 'FAQ' section within the same page by using: <a href="#faq">FAQ</a> and <section id="faq"> However, this is not working. Can anyone please guide me here ?

Saurabh Verma
  • 6,328
  • 12
  • 52
  • 84
  • Could you add your route configuration here? And do you expecting that faq template should be loaded inside faq section – Pankaj Parkar Apr 26 '15 at 12:59
  • This is my route configuration: when('/home', { templateUrl: 'components/home/home.html', controller: 'HomeController' }). In my home.html, I have links pointing to different sections of home.html – Saurabh Verma Apr 26 '15 at 14:09

2 Answers2

1

You can also use $anchorScroll (better solution). You can see an sample and more details here. I don't test ng-href but i think it is bad solution.

Community
  • 1
  • 1
Shimrra
  • 273
  • 2
  • 16
  • You can see an sample for the same problem in the link : http://stackoverflow.com/questions/14712223/how-to-handle-anchor-hash-linking-in-angularjs/14717011#14717011 – Shimrra Apr 26 '15 at 12:50
0

You should write in the href attribute #/faq, with a slash.

and another issue, is using ng-href, as written in angular docs(https://docs.angularjs.org/api/ng/directive/ngHref):

Using Angular markup like {{hash}} in an href attribute will make the link go to the wrong URL if the user clicks it before Angular has a chance to replace the {{hash}} markup with its value. Until Angular replaces the markup the link will be broken and will most likely return a 404 error. The ngHref directive solves this problem.

MoLow
  • 3,056
  • 2
  • 21
  • 41