Skip to content

Instantly share code, notes, and snippets.

@HAKASHUN
Created October 16, 2013 09:50
Show Gist options
  • Save HAKASHUN/7005357 to your computer and use it in GitHub Desktop.
Save HAKASHUN/7005357 to your computer and use it in GitHub Desktop.
AngularJSで作るShoppingCartのサンプル
<html ng-app>
<head>
<meta charset="UTF-8">
<title>Your Shopping Cart</title>
</head>
<body ng-controller="CartController">
<h1>Yout Shopping Cart</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="../bower_components/angular/angular.js"></script>
<script>
function CartController($scope) {
$scope.items = [
{title: 'Paint pots', quantity: 8, price: 3.95},
{title: 'Polka dots', quantity: 17, price: 12.95},
{title: 'Pebbles', quantity: 5, price: 6.95}
];
$scope.remove = function(index) {
$scope.items.splice(index, 1);
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment