Skip to content

Instantly share code, notes, and snippets.

@LukeMauldin
Created April 23, 2014 13:47
Show Gist options
  • Select an option

  • Save LukeMauldin/11215787 to your computer and use it in GitHub Desktop.

Select an option

Save LukeMauldin/11215787 to your computer and use it in GitHub Desktop.
'use strict'
function CalcModel (principal, rate, time) {
this.principal = principal;
this.rate = rate;
this.time = time;
this.totalInterest = function() {
//Hardcode return
return principal * rate * time;
}
}
var calcInterestApp = angular.module('calcInterestApp', []);
calcInterestApp.controller('calcInterestController', function($scope) {
//Set defaults
$scope.model = new CalcModel(10000, 5, 3);
});
<!DOCTYPE html>
<html ng-app="calcInterestApp">
<head>
<title>Interest Calculator</title>
<script src='@routes.Assets.at("javascripts/jquery-1.9.0.min.js")' type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src='@routes.Assets.at("javascripts/calcinterest.js")' type="text/javascript"></script>
</head>
<body ng-controller="calcInterestController">
<table>
<tbody>
<tr>
<td>
<label>Principal</label>
</td>
<td>
<input id="principal" ng-model="model.principal" />
</td>
</tr>
<tr>
<td>
<label>Rate</label>
</td>
<td>
<input id="rate" ng-model="model.rate" />
</td>
</tr>
<tr>
<td>
<label>Time</label>
</td>
<td>
<input id="time" ng-model="model.time" />
</td>
</tr>
</tbody>
</table>
<div>
Total Interest:
<input ng-model="model.totalInterest" readonly="readonly"/>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment