0
I’m starting to learn from Angularjs. In a simple function, I need to make the factorial of a number using Angularjs, but I cannot return the result on the screen (HTML page). Could someone help me?
<!DOCTYPE html>
<html ng-app="fatorialApp">
<head>
<meta charset="UTF-8" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
</head>
<body ng-controller="fatorialController">
<div>
<label>Número:</label>
<input type="text" ng-model="numero" placeholder="Calcular o fatorial">
<hr>
<h1>{{ resultado }}</h1>
</div>
<script>
var app = angular.module('fatorialApp', []);
app.controller('fatorialController', function($scope) {
$scope.resultado = function() {
var resultadoDoFatorial = 1;
for (var i = 1; i <= $scope.numero; i++) {
resultadoDoFatorial = resultadoDoFatorial * i;
}
return resultadoDoFatorial;
}
});
</script>
</body>
</html>