Skip to content

Instantly share code, notes, and snippets.

@SFantasy
Last active August 29, 2015 14:08
Show Gist options
  • Save SFantasy/75dc0c79f60b0f99eaf8 to your computer and use it in GitHub Desktop.
Save SFantasy/75dc0c79f60b0f99eaf8 to your computer and use it in GitHub Desktop.
Angular - Shopping Cart
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-app ng-controller="CartController">
<h1>Shopping Cart</h1>
<div ng-repeat="item in items">
<span>{{ item.title }}</span>
<input type="text" ng-model="item.quantity">
<span>{{ item.price | currency }}</span>
<span>{{ item.price * item.quantity }}</span>
<button ng-click="remove($index)">Remove</button>
</div>
</body>
</html>
function CartController ($scope) {
$scope.items = [
{
title: 'Nike Air Max 60',
quantity: 2,
price: 60
},
{
title: 'Air Jordan 13',
quantity: 1,
price: 80
}
];
$scope.remove = function (index) {
$scope.items.splice(index, 1);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment