When I click a specific element on the table (code with $scope below), I want to retrieve the information of that element (say "apple" in the example code).
Currently, I'm having trouble search up an element in the $scope.studentsObj and attach an onClick to all of them (this includes the one being added by the $scope.studentsObj.push function.)
Also, right now when I use $scope.studentsObj.push, it always goes to the next row, how do I push element to specific key value? For example, when I add "first: apple, last: juice" , "first: apple, last: pie" row, it should be replaced by "first: apple, last: juice".
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<style>
table, th, td {
border: 1px solid black;
}
</style>
<body>
<div ng-app="myApp" ng-controller="myController">
<h1>Table of Names/h1>
<table>
<th> <h2>First Name</h2></th> <th> <h2>Last Name</h2></th>
<tr ng-repeat="student in studentsObj">
<td ng-repeat="(key, value) in student"> {{value}} </td>
</tr>
</table>
<script>
var app = angular.module('myApp', []);
app.controller('myController', function($scope) {
$scope.studentsObj =
[ {first: "apple", last: "pie"},
{first: "dance", last: "marathon"},
{first: "tom", last: "boy"}],
$scope.studentsObj.push({first:"karen"}),
$scope.studentsObj.push({first:,last:"smith"});
});
</script>
</body>
</html>
ng-click="addStudent()and add anaddStudentfunction to your$scopeobject in the controller