How to remove an item from an array in AngularJS scope?

后端 未结 10 1749
梦毁少年i
梦毁少年i 2020-11-27 09:10

Simple to-do list, but with a delete button on list page for each item:

Relevant template HTML:


          


        
10条回答
  •  臣服心动
    2020-11-27 09:40

    If you have any function associated to list ,when you make the splice function, the association is deleted too. My solution:

    $scope.remove = function() {
        var oldList = $scope.items;
        $scope.items = [];
    
        angular.forEach(oldList, function(x) {
            if (! x.done) $scope.items.push( { [ DATA OF EACH ITEM USING oldList(x) ] });
        });
    };
    

    The list param is named items. The param x.done indicate if the item will be deleted.

    Another references: Another example

    Hope help you. Greetings.

提交回复
热议问题