Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created November 2, 2013 06:42
Show Gist options
  • Save ynonp/7276268 to your computer and use it in GitHub Desktop.
Save ynonp/7276268 to your computer and use it in GitHub Desktop.
Angular lab1
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<title>CoolShop</title>
<style>
.item label {
margin: 10px;
display: inline-block;
min-width: 250px;
}
.item input {
float: right;
}
.total {
margin-top: 20px;
}
.total span {
margin-left: 100px;
}
</style>
</head>
<body>
<div ng-controller="Cart">
<div class="item">
<label>
Shoes:
<input type="text" value="{{shoes}}" />
</label>
</div>
<div class="item">
<label>
Hats:
<input type="text" value="{{hats}}" />
</label>
</div>
<div class="item">
<label>
Plates:
<input type="text" value="{{plates}}" />
</label>
</div>
<div class="total">
<button>Calculate</button>
<span>{{total}}</span>
</div>
</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.5/angular.min.js"></script>
<script src="main.js"></script>
</body>
</html>
var myApp = angular.module('MyApp', []);
myApp.controller('Cart', ['$scope', function($scope) {
$scope.text = 'Welcome To Angular';
$scope.shoes = 2;
$scope.hats = 4;
$scope.plates = 11;
$scope.total = 0;
$scope.calculate_total = function() {
$scope.total = Number($scope.shoes) + Number($scope.hats) + Number($scope.plates);
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment