-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex7.html
More file actions
59 lines (57 loc) · 1.47 KB
/
ex7.html
File metadata and controls
59 lines (57 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html ng-app="countryTableApp">
<script src="angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('countryTableApp', []);
app.controller('myCtrl', function($scope) {
/* Array */
$scope.ctryArr = [
{"name": "China", "population": "1382323332"},
{"name": "India", "population": "1326801576"},
{"name": "United States", "population": "324118787"}
];
/* Add new */
$scope.addCountry = function() {
/*$scope.ctryArr.push($scope, [country.newName,country.newPop]);*/
console.log($scope.ctryArr);
$scope.ctryArr.push({ 'name':$scope.newName, 'population': $scope.newPop});
$scope.newName = "";
$scope.newPop = "";
};
/* Remove */
$scope.remove = function(country) {
var i = $scope.ctryArr.indexOf(country);
$scope.ctryArr.splice(i, 1);
}
});
</script>
<body>
<div ng-controller="myCtrl">
<form ng-submit="addCountry()">
<table>
<thead>
<tr>
<th>Country Name</th>
<th>Population</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="country in ctryArr">
<td>{{country.name}}</td>
<td>{{country.population}}</td>
<td><button ng-click="remove(country)">Remove</button></td>
</tr>
</tbody>
<tfoot>
<tr>
<td><input type="text" ng-model="newName" required /></td>
<td><input type="number" ng-model="newPop" required /></td>
<td><input type="submit" value="Add" /></td>
</tr>
</tfoot>
</table>
</form>
</div>
</body>
</html>