1

我正在构建一个购物应用程序。在应用程序的某个地方,我需要显示用户的购物车并让他编辑它。我有删除按钮不工作...

在此处输入图像描述

<html xmlns="http://www.w3.org/1999/xhtml" ng-app>
<head>
<title>Your Shopping Cart</title>
</head>
<body ng-controller="CartController">
<h1>Your Order</h1>
<div ng-repeat="item in items">
    <span>{{item.title}}</span>
    <input ng-model="item.quantity" />
    <span>{{item.price | currency}}</span>
    <span>{{item.price * item.quantity | currency}}</span>
    <button ng-click="remove($index)">Remove</button>
</div>


<script src="js/angular.min.js"></script>
<script>
    function CartController($scope) {
        $scope.items = [
            {title:'Srimad Bhagwat', quantity:8, price:3.95},
            {title:'rupa chintamani', quantity:17, price:12.95},
            {title:'ram charit manas', quantity:5, price:6.95}
        ];
    };

    $scope.remove = function (index) {
        $scope.items.splice(index, 1);
    }
</script>

4

1 回答 1

5

将您的 $scope.remove 移动到 CartController 的 { } 中

于 2013-07-17T17:06:46.563 回答