angular.module('mainApp', [])
.controller('MainCtrl', function($scope) {
})
.filter('factorial', function() {
return function factorial(n) {
return n === 0 ? 1 : n * factorial(n - 1);
}
});
<!DOCTYPE html>
<html ng-app="mainApp">
<head>
<meta charset="utf-8" />
<title>AngularJS Factorial Plunker</title>
<script>
document.write('<base href="' + document.location + '" />');
</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.9/angular.js" data-semver="1.4.9"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<label for="fact">Your value</label>
<input id="fact" ng-model="Value" ng-init="Value=0" /> as a factorial {{Value | factorial}}
</body>
</html>
/* Put your css in here */