ng 单击<tr>什么都不做

ng-click on <tr> doing nothing

本文关键字:什么 tr 单击 ng      更新时间:2023-09-26

我已经查阅了这些相关文章,但提出的解决方案不起作用:

  • 带角度的可点击引导行
  • 在ng-repeat中向ng-click功能添加参数似乎不起作用
  • 角度 ng 单击在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的一部分,因此它不会执行任何操作。

您可以将其添加到控制器中:

$scope.alert = function(message) { alert(message); }