首先得创建一个json文件把入到里面
[{"name":"张三","age":15,"sex":"男"},
{"name":"李四","age":21,"sex":"女"},
{"name":"王五","age":22,"sex":"男"},
{"name":"赵六","age":23,"sex":"女"}]
<!DOCTYPE html>
<html><head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="../agulajs/angular.js" ></script>
<script>
var app=angular.module("myApp",[]);
//注入$http对象
app.controller("myCtrl",function($scope,$http){
//调用$http请求服务器
$http({
method:"get",
url:"haha.json"
}).then(function success(response){
$scope.users=response.data;
},function error(){
$scope.users=null;
});
//删除用户
$scope.delete=function(index){
$scope.users.splice(index,1)
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<h3>我的用户表</h3>
<table border="1px solid blue" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th>用户名</th>
<th>年龄</th>
<th>性别</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td>{{user.name}}</td>
<td>{{user.age}}</td>
<td>{{user.sex}}</td>
<td><button ng-click="delete($index)">删除</button></td>
</tr>
</tbody>
</table>
</center>
</body>
</html>