Remove item from list after filtering

后端 未结 1 648
臣服心动
臣服心动 2021-02-19 22:09

I have the following issue:

I\'ve create a list that allow the user to delete an item from list, as following:

相关标签:
1条回答
  • 2021-02-19 22:49

    As mentioned by @pkozlowski.opensource, you can't depend on $index to identify an item in an array in this way. I would make the following changes:

    HTML:

    <td><a ng-click="deleteWish(coupon)"><i class="icon-trash"></i></a></td>
    

    JS:

    $scope.deleteWish = function (coupon) {
        var index = $scope.coupons.indexOf(coupon);
        if (index != -1) {
            $scope.coupons.splice(index, 1);
        }
    }
    

    Here is a working Plunker: http://plnkr.co/edit/b0b2cYGsM5wtw8hIrQB5?p=preview

    0 讨论(0)
提交回复
热议问题