angular.js - 请教在angular里从多维对象数组里删除某个对象数组的问题

浏览:31日期:2023-01-18

问题描述

评论展示是ng-repeat,comment in comments。有删除评论功能,ng-click之后,把comment传到删除函数里,然后从comments里把这个comment删掉,这个删除的语句应该怎么写呢?谢谢!

问题解答

回答1:

<p ng-repeat=’comment in comments’ ng-click=’del($index,comments)’>{{comment}}</p>$scope.delete=function(key,arr){ arr.splice(key,1);}回答2:

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) }})

相关文章: