AngularJS: Cart example
HTML
<link rel="stylesheet" href="http://d1e24pw9mnwsl8.cloudfront.net/c/bootstrap/css/bootstrap.min.css">
<h2>Shopping Cart Example</h2>
<div ng:controller="CartForm">
<table class="table">
<tr>
<th>Description</th>
<th>Qty</th>
<th>Cost</th>
<th>Total</th>
<th></th>
</tr>
<tr ng:repeat="(key,item) in cart">
<td>
<input type="text" ng:model="item.description" class="input-small">
</td>
<td>
<input type="number" ng:model="item.qty" ng:required class="input-mini">
</td>
<td>
<input type="number" ng:model="item.cost" ng:required class="input-mini">
</td>
<td>{{item.qty * item.cost | currency}}</td>
<td>[<a href ng:click="removeItem(key)">X</a>]</td>
</tr>
</table>
</div>
JavaScript
function CartForm($scope) {
$scope.cart = {
"4": {
"cost": 802.85,
"description": "test",
"qty": 1
},
"5": {
"cost": 802.85,
"description": "test",
"qty": 1
}
};
$scope.removeItem = function (item) {
delete $scope.cart[item];
}
}