我查阅了这些相关文章,但所提供的解决方案不起作用:
- Clickable bootstrap row with angular
- Adding parameter to ng-click function inside ng-repeat doesn't seem to work
- Angular ng-click not working in div
这是我的 plunkr::http://plnkr.co/edit/kha6mAKDBtrY0XtTc6Wp?p=preview
<body ng-controller="MainCtrl">
<table>
<caption>Troubles with ng-repeat and ng-click</caption>
<thead>
<tr>
<th>Name</th>
<th>Occupation</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee in employees" ng-click="alert('hi')">
<td>{{employee.name}}</td>
<td>{{employee.occupation}}</td>
</tr>
</tbody>
</table>
var app = angular.module("plunker", []);
app.controller("MainCtrl", function($scope) {
$scope.employees = [
{
name: "John Doe",
occupation: "Miner"
},
{
name: "Theressa",
occupation: "Construction Worker"
}
]
});
最佳答案
它确实有效,但 alert
不是您的 $scope
的一部分,因此它不会执行任何操作。
您可以将其添加到 Controller 中:
$scope.alert = function(message) { alert(message); }
关于javascript - ng-click <tr> 不执行任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29088200/