AngularJS ng-href does not go to link

code-sushi picture code-sushi · Aug 29, 2014 · Viewed 18.3k times · Source

I've checked the docs and the ng-href not working thread on here already but I'm stumped.

Does ng-href require a full path? Mine currently looks like <a ng-title="{{title.text}}" ng-id="{{id.num}}" ng-href="/page.php#param:{{id.num}}"><span>go here</span></a>, but when I click on it, while it changes the URL in the address bar of the browser correctly (and it's a legitimate URL; I can hit "enter" in the address bar and it will "go there"), it does not actually GO TO that page.

What's going wrong? Do I need to combine this with an ng-click of some sort? And if so, why?

UPDATE: The link is going to the same page from which it is being called, but with a different parameter for a different data record display. I think that may have something to do with it ...

Answer

Alexis Gamarra picture Alexis Gamarra · Apr 20, 2015

The simplest way to do this is adding target="_self", in your case this is the solution:

<a ng-title="{{title.text}}" ng-id="{{id.num}}"
 ng-href="/page.php#param:{{id.num}}" target="_self">
 <span>go here</span>
</a>

No ng-click and no AngularJS function are required.