我有一张桌子,用引导程序设计。该表的内容是使用 Angular.js 填充的。如何使一行可点击,以便它调用范围内的函数?
以下代码对我不起作用(ng-click 部分):
桌子:
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="ingredient in ingredients" ng-click="setSelected({{$index}});">
<td>{{ ingredient.name }}</td>
<td>{{ ingredient.status }}</td>
</tr>
</tbody>
</table>
控制器:
$scope.setSelected = function(index) {
$scope.selected = $scope.ingredients[index];
console.log($scope.selected);
};