<!DOCTYPE html>
<html ng-app="app1">
<head>
<title>splice</title>
</head>
<body >
<div ng-controller="ctr">
<div ng-repeat="item in obj">
<p><span>{{item.title}}</span><span>{{item.content}}</span> <span ng-click="del(item)">X</span></p>
</div>
</div>
<script src="https://cdn.bootcss.com/angular.js/1.2.0/angular.js"></script>
<script type="text/javascript">
var app=angular.module("app1",[])
app.controller("ctr",function($scope){
$scope.obj=[
{"title":"1111","content":"one"},
{"title":"2222","content":"two"},
{"title":"3333","content":"three"}
];
$scope.del=function(item){
for(var i=0;i<$scope.obj.length;i++){
if($scope.obj[i]==item){
$scope.obj.splice(i,1);
}
}
}
})
</script>
</body>
</html>
网友评论