var app = angular.module('App', []);
app.controller('Ctrl', function($scope) {
$scope.table = {
row: [{
fields: [{
title: "Your name",
name: "John",
id: 'name'
}, {
title: "Your second name",
name: "Doe",
id: 'secondName'
}, {
title: "Your age",
name: 26,
id: 'age'
}, {
title: "Your sex",
name: "Male",
id: 'sex'
}]
}, {
fields: [{
title: "Your name",
name: "Kevin",
id: 'name'
}, {
title: "Your second name",
name: "Parker",
id: 'secondName'
}, {
title: "Your age",
name: 32,
id: 'age'
}, {
title: "Your sex",
name: "Male",
id: 'sex'
}]
}, {
fields: [{
title: "Your name",
name: "Barbara",
id: 'name'
}, {
title: "Your second name",
name: "Streisand",
id: 'secondName'
}, {
title: "Your age",
name: 60,
id: 'age'
}, {
title: "Your sex",
name: "Female",
id: 'sex'
}]
}, {
fields: [{
title: "Your name",
name: "Linda",
id: 'name'
}, {
title: "Your second name",
name: "Lorry",
id: 'secondName'
}, {
title: "Your age",
name: 20,
id: 'age'
}, {
title: "Your sex",
name: "Female",
id: 'sex'
}]
}]
};
$scope.showIndex = function(name, index) {
$scope.showResult = name + ' in the row number ' + index;
}
});
<!DOCTYPE html>
<html lang="en" ng-app="App">
<head>
\t <meta charset="UTF-8">
\t <title>Document</title>
\t <link rel="stylesheet" href="style.css">
\t <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src='script.js'></script>
</head>
<body ng-controller="Ctrl">
\t <table>
\t \t <thead>
\t \t \t <tr>
\t \t \t \t <th ng-repeat='header in table.row[0].fields'>{{header.title}}</th>
\t \t \t </tr>
\t \t </thead>
\t \t <tbody>
\t \t \t <tr ng-repeat='row in table.row'>
\t \t \t \t <td ng-click="showIndex(field.name, $parent.$index)" ng-repeat='field in row.fields'>{{field.name}}</td>
\t \t \t </tr>
\t \t </tbody>
\t </table>
<br>
<b>{{showResult}}</b>
\t </body>
</html>
に
$parent.$index
代わりの$index
を使用する必要がありますはい、それは働きます!ありがとう – YoroDiallo