i want populate webpage using ng-repeat , following array:
var array = [{name: bill, age: 12, number: 1}, {name: tyrone, age: 11, number: 2}, {name: sarah, age: 14, number: 3}];
i want able push button , return angular controller name or number value given person. don't know how though i've tried both button , input attempts no success. can see 1 of attempts in 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 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) }); } }
you can pass data want use in function's parameters:
<button ng-click="age(a.age)">this age</button>
$scope.age = function(age) { $http.post('api/age', {age: age}) .success(function (response) { console.log(response) }) .error(function (error) { console.log(error) }); }