AngularJS ngRepeat element removal

后端 未结 5 1264
迷失自我
迷失自我 2021-01-30 08:19

There are quite a few questions on how to implement item removal inside ngRepeat directive, and as I figured out, it comes down to using ngClick and triggering

5条回答
  •  天涯浪人
    2021-01-30 08:51

    A very simple and convenient way that works cross-browser is to use the 'remove' utility method from the library lodash.

    {{ phone }} Remove

    In your controller you declare then

    //inject lodash dependency
    
    //declare method in scope
    $scope.removeItem = function(list, item){
       lodash.remove(list,function(someItem) { return item === someItem});
    }
    

    You may of course use indexes if you like. See https://lodash.com/docs#remove

提交回复
热议问题