AngularJS - Shopping Cart
Shopping Cart forked with increase and decrease buttons.
HTML
<link rel="stylesheet" href="http://d1e24pw9mnwsl8.cloudfront.net/c/bootstrap/css/bootstrap.min.css">
<h2>Shopping Cart</h2>
<div ng-controller="CartForm">
<table class="table">
<tr ng-repeat="item in invoice.items">
<td><select type="number" ng:-model="item.qty" class="input-mini"/>
<option>1</option>
<option>2</option>
<option>3</option>
</td>
<td>{{item.qty * item.cost | currency}}</td>
</tr>
<tr>
</tr>
</table>
</div>
JavaScript
function CartForm($scope) {
$scope.invoice = {
items: [
{
id: 1,
qty: 1,
name: 'item',
cost: 9.95
},
]
};
$scope.addItem = function() {
$scope.invoice.items.push({
qty: 1,
name: '',
cost: 0
});
};
$scope.total = function() {
var total = 0;
angular.forEach($scope.invoice.items, function(item) {
total += item.qty * item.cost;
});
return total;
}
}