2

I'm trying to create a link to each id using angularjs ng-href but when I refresh the page, the links don't show up. I even closed the browser and cleared the cache yet nothing is happening. Here is my current code:

 <tr ng-repeat="parcel in parcels">
<td><a ng-href="http://www.proj.com/{{ parcel.id }}/edit/"/>{{ parcel.
 id }}</td>
<td>{{ parcel.tracking_id }}</td>
<td>{{ parcel.shipper_ref_no }}</td>                                     

$scope.parcels = [];
$scope.scans = [];
$scope.missings = [];
$scope.excludeds = [];

$scope.parcels = Outbound.summaryPageData.parcels;
$scope.scans = Outbound.summaryPageData.scans;
$scope.missings = Outbound.summaryPageData.missings;
$scope.excludeds = Outbound.summaryPageData.excludeds;


 });
3
  • How do you know ng-href is not working? Maybe the problem is with your ng-repeat directive. Please post your controller's code. Commented Aug 5, 2014 at 14:32
  • Can we see you javascript? At least the part that works with this snippet. Commented Aug 5, 2014 at 14:33
  • I've posted my controller Commented Aug 5, 2014 at 14:35

1 Answer 1

8

I think it's a simple HTML syntax error - the <a> tag has no content. Try changing this:

<a ng-href="http://www.proj.com/{{ parcel.id }}/edit/"/>{{ parcel.id }}

to:

<a ng-href="http://www.proj.com/{{ parcel.id }}/edit/">{{ parcel.id }}</a>
Sign up to request clarification or add additional context in comments.

6 Comments

Yes, this moment is clearly described here: https://docs.angularjs.org/api/ng/directive/ngHref
Worked. thanks for that. I got my ng-href straight from the angularjs documentation and it wasn't working. Thanks. I'll accept your answer when I can :)
Well, the way I see it, this has nothing to do with href vs ng-href at all, but with the fact that <a> tags need content to show up in the page (and I think strictly speaking they must not be self closing according to HTML specs). The documentation seems to be a bit misleading here.
FYI, I already sent a pull request to the AngularJS GitHub project to fix this documentation issue.
Does it require a full path? Mine looks like <a ng-href="/page.php#param:{{myparam}}"><span> content 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. Do I need to combine this with an ng-click of some sort? And if so, why?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.