评论展示是ng-repeat,comment in comments。有删除评论功能,ng-click之后,把comment传到删除函数里,然后从comments里把这个comment删掉,这个删除的语句应该怎么写呢?谢谢!
<p ng-repeat='comment in comments' ng-click='del($index,comments)'>{{comment}}</p> $scope.delete=function(key,arr){ arr.splice(key,1); }
html
<p ng-repeat='comment in comments' ng-click='delete($index)'>{{comment}}</p>
js
app.controller('myCtrl', function($scope) { $scope.comments=[1,2,3,4] $scope.delete=function(i){ $scope.comments.splice(i,1) } })
html
js