search

Home  >  Q&A  >  body text

angular.js - Ask about deleting an object array from a multi-dimensional object array in angular

Comment display is ng-repeat, comment in comments.
There is a function to delete comments. After ng-click, the comment is passed to the delete function, and then the comment is deleted from comments. How should the delete statement be written?
Thank you!

给我你的怀抱给我你的怀抱2870 days ago690

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-05-15 17:01:30

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

    reply
    0
  • 怪我咯

    怪我咯2017-05-15 17:01:30

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

    reply
    0
  • Cancelreply