[英]Angular: How to make whole table row clickable within ng-repeat?
I have a table.我有一张桌子。
<tbody>
<tr ng-repeat="star in stars">
<td>
<a ng-href="/#/stars/{{star.id}}">{{star.id}}</a>
</td>
<td>{{star.name}}</td>
</tr>
</tbody>
It renders entities.它呈现实体。 So far the first column is clickable.
到目前为止,第一列是可点击的。 I want to make the whole table row (
<tr>
) clickable.我想让整个表格行(
<tr>
)可点击。 How can I do it?我该怎么做?
You can place ng-click
inside of your <tr>
and then have a function in your controller that redirects to the correct URL.您可以将
ng-click
放在<tr>
,然后在控制器中设置一个重定向到正确 URL 的函数。 Like this:像这样:
HTML HTML
<tbody>
<tr ng-repeat="star in stars" ng-click="goToLink(star)">
<td>{{star.id}}</td>
<td>{{star.name}}</td>
</tr>
</tbody>
Controller控制器
$scope.goToLink = function(star) {
$location.path('#/stars/' + star.id);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.