angular 初体验
<!DOCTYPE html>
<html>
<body>
<div ng-app="" ng-controller="personController">
名: <input type="text" ng-model="person.firstName"><br>
姓: <input type="text" ng-model="person.lastName"><br>
<br>
<div>
<table>
<tr ng-repeat = "(key,item) in arr " >
<td>{{key}}</td>
<td>{{item.name}}</td>
<td>{{item.age}}</td>
<td>
<button id="item.id" ng-click="remove(key)">remove</button>
</td>
</tr>
</table>
</div>
</div>
<script>
function personController($scope) {
$scope.person = {
firstName: "kobe",
lastName: "bryant",
};
$scope.arr = [
{
id:0,
name:'bryant',
age:42
},
{
id:1,
name:'lebron',
age:36
}
]
$scope.fullName = function() {
var x = $scope.person;
return x.firstName + " " + x.lastName;
}
$scope.remove = function(id) {
alert(id)
$scope.arr.splice(id, 1)
}
}
</script>
<script src="//www.runoob.com/try/angularjs/1.2.5/angular.min.js"></script>
</body>
</html>
- result