Last active
August 29, 2015 14:08
-
-
Save SFantasy/75dc0c79f60b0f99eaf8 to your computer and use it in GitHub Desktop.
Angular - Shopping Cart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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