I want to populate a webpage using ng-repeat and the following array:
var array = [{name: Bill, age: 12, number: 1}, {name: Tyrone, age: 11, number: 2}, {name: Sarah, age: 14, number: 3}];
I want to be able to push a button and return to my Angular controller the name or number value for the given person. I don't know how to do this though I've tried with both button and input attempts with no success. You can see one of the attempts in the example code below.
<div class="container">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th colspan="1" class="text-center">
Name
</th>
<th colspan="1" class="text-center">
Age
</th>
<th colspan="1" class="text-center">
Number
</th>
</tr>
</thead>
<tbody filter-list="search"ng-repeat="a in array">
<tr>
<td class="col-xs-6 col-sm-6 col-md-6 col-xl-6">
{{a.name}}
</td>
<td class="col-xs-4 col-sm-4 col-md-4 col-xl-4">
<button ng-click="Age()" ng-model="a.age">This Age</button>
</td>
<td class="col-xs-2 col-sm-2 col-md-2 col-xl-2">
<input type="button" name="number" ng-click="Number()" ng-model="a.number" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
My controller is as follows:
angular.module('startupApp')
.controller('ManageCardCtrl', function ($scope, $location, $http) {
var array = [{name: Bill, age: 12, number: 1}, {name: Tyrone, age: 11, number: 2}, {name: Sarah, age: 14, number: 3}];
$scope.Age = function(){
$http.post('api/age', {age: $scope.age})
.success(function (response) {
console.log(response)
})
.error(function (error) {
console.log(error)
});
}
$scope.number = function(){
$http.post('api/number', {number: $scope.number})
.success(function (response) {
console.log(response)
})
.error(function (error) {
console.log(error)
});
}
}