【发布时间】:2017-11-25 05:41:12
【问题描述】:
如何使用 ng-click 指令从 HTML 表格中获取单元格值?
我需要实现使用 ng-click 捕获行值的最佳方法
HTML 表格:
<div ng-controller="myController">
<table>
<thead>
<th>Id</th>
<th>Name</th>
<th>Age</th>
<th>Action</th>
</thead>
<tbody>
<tr ng-repeat="item in stutents">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.age}}</td>
<td><button type="button" ng-click="getCellValue()">View</button></td>
</tr>
</tbody>
</table>
</div>
我的控制器:
var app = angular.module('firstApp', []);
app.controller('myController', function($scope){
$scope.stutends = {};
//array values... etc
$scope.getCellValue = function() {
//i want values index, ej. table[0] = id, table[1] = name etc... its posible ?, ej
//var name = table[1]
console.log(name);
}
});
【问题讨论】:
标签: html angularjs function html-table each