我正在构建购物应用。在应用程序的某个地方,我需要显示用户的购物车并让他编辑它。 我有删除按钮但无法正常工作 ...
<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>
答案 0 :(得分:5)
将$ scope.remove移动到CartController&#39; s {}
中