Angularjs ngClick是否在放入ngRepeat时将click处理程序附加到每个项目
我在一个表中显示了大约500多行数据,并使用ngClick在每一行上显示关于每一行的更多信息:Angularjs ngClick是否在放入ngRepeat时将click处理程序附加到每个项目,angularjs,Angularjs,我在一个表中显示了大约500多行数据,并使用ngClick在每一行上显示关于每一行的更多信息: <tr ng-repeat="row in displayData.rows track by $index"> <td><span ng-click="orderDetails(row.orderNumber)" class="glyphicon glyphicon-plus"></span></td>&
<tr ng-repeat="row in displayData.rows track by $index">
<td><span ng-click="orderDetails(row.orderNumber)" class="glyphicon glyphicon-plus"></span></td><td>{{row.orderNumber}}</td><td>{{row.shiptoCompany}}</td><td>{{row.orderTime}}</td><td>{{row.clientID}}</td><td>{{row.shiptoAttention}}</td><td>{{row.shipMethod}}</td><td>{{row.whenLastShipped}}</td>
</tr>
{{row.orderNumber}{{row.shiptoCompany}{{row.orderTime}{{row.clientID}{{row.shiptoAttention}{{row.shiptoMethod}{{row.whenLastShipped}
使用vanilla JS,我只需在整个表上放置一个click处理程序,并使用事件来确定单击了哪一行。有没有办法用Angular做同样的事情,或者Angular已经有效地做到了?我不想在页面上附加500多个点击处理程序,如果这是我正在做的和/或有更好的方法获得相同的结果 您可以对整个表而不是每一行使用单个
ng单击
html:
您可以对整个表而不是每一行使用单个ng单击
html:
您可以对整个表而不是每一行使用单个ng单击
html:
您可以对整个表而不是每一行使用单个ng单击
html:
谢谢那正是我想要的。谢谢!那正是我想要的。谢谢!那正是我想要的。谢谢!这正是我想要的。
<body ng-app="myApp">
<div ng-controller="MyController">
<table ng-click="tableClick($event)">
<tr ng-repeat="row in rows track by $index" style="background:#666">
<td>{{row}}</td>
</tr>
</table>
</div>
</body>
var app = angular.module('myApp',[]);
app.controller('MyController', function($scope)
{
$scope.rows = [1,2,3,4,5];
$scope.tableClick = function($event)
{
var scope = angular.element($event.target).scope();
console.log(scope.$index);
};
});