Created
June 23, 2016 07:30
-
-
Save nonZero/34082b5ced50680fe2ed49f4418aa317 to your computer and use it in GitHub Desktop.
angular store 1
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 lang="en" ng-app="store"> | |
<head> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" href="bootstrap/css/bootstrap.css"> | |
<title>Our Store!!!</title> | |
</head> | |
<body> | |
<div class="container" ng-controller="StoreCtrl"> | |
<h1> | |
My Awesome Store! | |
</h1> | |
<div class="row"> | |
<div class="col-sm-8"> | |
<div class="panel panel-default"> | |
<div class="panel-heading"> | |
<h3 class="panel-title">Inventory</h3> | |
</div> | |
<ul class="list-group"> | |
<li class="list-group-item" ng-repeat="product in inventory"> | |
<button class="btn btn-success btn-xs" | |
ng-click="addToCart(product)"><i class="glyphicon glyphicon-plus"></i></button> | |
{{product.title}} | |
<span class="badge">{{product.price|currency}}</span> | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div class="col-sm-4"> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h3 class="panel-title">My Cart</h3> | |
</div> | |
<ul class="list-group"> | |
<li class="list-group-item" ng-repeat="item in cart"> | |
{{item.product.title}} | |
{{item.product.price|currency}} | |
X <input type="number" ng-model="item.amount" min="1" max="100"> | |
= {{item.product.price * item.amount|currency}} | |
</li> | |
<li class="list-group-item"> | |
Items: 0; Total: <b>$0.00</b> | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script src="angular.js"></script> | |
<script src="store.js"></script> | |
</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
"use strict"; | |
var m = angular.module("store", []); | |
m.controller('StoreCtrl', function ($scope) { | |
$scope.inventory = [ | |
{id: '111', title: 'milk', price: 1.2}, | |
{id: '123', title: 'yellow cheese', price: 2.1}, | |
{id: '456', title: 'soft cheese', price: 3.0}, | |
{id: '426', title: 'apples (kg)', price: 2.52}, | |
]; | |
$scope.cart = []; | |
$scope.addToCart = function (product) { | |
// TODO: check if id already exists | |
$scope.cart.push( | |
{product: product, amount: 1} | |
); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment