table row like a link with ng-href

5,689 views
Skip to first unread message

Mauro Cacicia

unread,
Feb 21, 2014, 11:53:48 AM2/21/14
to ang...@googlegroups.com
hi guys, i'm new with angular and i have this problem,
i need to use ng-href on one entire table row created with ng-repeat, to be more clear i need to do something like that:


<tr ng-repeat="res in result">
    <a ng-href="/somwhere/{{res.id}}>
        <td>{{res.id}}</td>
        <td>{{res.ragioneSociale}}</td>
        <td>{{res.indirizzo}}</td>
        <td>{{res.codiceFiscale}}</td>
        <td>{{res.tipoSocieta}}</td>
        <td>{{res.attivita}}</td>
    </a>
   </tr>


i really need to use the ng-href because part of the url have to change dinamically in base at what row will be clicked.
thanks

Vanya Dineva

unread,
Feb 21, 2014, 1:37:03 PM2/21/14
to ang...@googlegroups.com
Hi Mauro,


first of all you forgot to close the double quotes for the ng-href:
   <a ng-href="/somwhere/{{res.id}}>
should be
   <a ng-href="/somwhere/{{res.id}}">

Second, <a> element as a direct descendent of a <tr> is not valid html. Try instead to have the contents of each <td> in the <tr> wrapped in a link:


<tr ng-repeat="res in result">
        <td><a ng-href="/somwhere/{{res.id}}"> {{res.id}} </a></td>
        <td><a ng-href="/somwhere/{{res.id}}"> {{res.ragioneSociale}} </a></td>
        <td><a ng-href="/somwhere/{{res.id}}"> {{res.indirizzo}} </a></td>
        <td><a ng-href="/somwhere/{{res.id}}"> {{res.codiceFiscale}} </a></td>
        <td><a ng-href="/somwhere/{{res.id}}"> {{res.tipoSocieta}} </a></td>
        <td><a ng-href="/somwhere/{{res.id}}"> {{res.attivita}} </a></td>
</tr>


Hope this solves your problem

Luke Kende

unread,
Feb 22, 2014, 2:37:38 AM2/22/14
to ang...@googlegroups.com
Have you tried ng-click?

<tr ng-click="goTo(res.id)" style="pointer:cursor">
         <td>{{res.id}}</td>
        <td>{{res.ragioneSociale}}</td>
        <td>{{res.indirizzo}}</td>
        <td>{{res.codiceFiscale}}</td>
        <td>{{res.tipoSocieta}}</td>
        <td>{{res.attivita}}</td>
</tr>

$scope.goTo = function (id){
  location.href = '/somewhere/' + id ;

Steve Jackson

unread,
Feb 22, 2014, 9:40:44 AM2/22/14
to ang...@googlegroups.com
+1 for ng-click!

Avinash Pratap

unread,
Feb 17, 2018, 1:26:43 AM2/17/18
to Angular and AngularJS discussion
it workes for me when  style="cursor:pointer;"
Reply all
Reply to author
Forward
0 new messages