IEnableMuch: Amortization Calculator
This is the computation routine for a real estate app
I made a real estate app long time ago(2003, made in VB6), what it don't compute then is how long you will pay something based on your budget. A new feature
Author: Michael Buen
HTML
<body ng-app="App" ng-controller="Controller">
<div>Price</div>
<div><input type="numeric" ng-model="product.price" style="text-align: right"></div>
<div>Discount</div>
<div><input type="numeric" ng-model="product.discount" percent style="text-align: right">%</div>
<p></p>
<div>Discounted Price: {{product.price * (1-product.discount) | number}}</div>
<hr>
{{product.price | number}} X {{product.discount}} = {{product.price * (1-product.discount) | number}}
</body>
JavaScript
var myApp = angular.module('App', []);
myApp.directive("percent", function($filter){
var p = function(viewValue){
var m = viewValue.match(/^(\d+)\/(\d+)/);
if (m != null)
return $filter('number')(parseInt(m[1])/parseInt(m[2]), 4);
return $filter('number')(parseFloat(viewValue)/100, 4);
};
var f = function(modelValue){
return $filter('number')(parseFloat(modelValue)*100, 2);
};
return {
require: 'ngModel',
link: function(scope, ele, attr, ctrl){
ctrl.$parsers.unshift(p);
ctrl.$formatters.unshift(f);
}
};
});
myApp.controller('Controller',['$scope', function($scope) {
$scope.product = {
price : 10000,
discount : 0.25
};
}]);