Angularjs删除按钮不起作用

时间:2013-07-17 16:58:57

标签: angularjs

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

enter image description here

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

1 个答案:

答案 0 :(得分:5)

将$ scope.remove移动到CartController&#39; s {}