Skip to content

Instantly share code, notes, and snippets.

@alexandreaquiles
Created November 14, 2016 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandreaquiles/a14a8f73081c9c097826b3e55e2f601a to your computer and use it in GitHub Desktop.
Save alexandreaquiles/a14a8f73081c9c097826b3e55e2f601a to your computer and use it in GitHub Desktop.
Cálculo de IMC com Angular usando MVC
<!DOCTYPE html>
<html ng-app="imcApp">
<head>
<script src="https://code.angularjs.org/1.3.5/angular.min.js"></script>
</head>
<body ng-controller="ImcController">
<label>Peso <input ng-model="peso"/> kg</label><br/>
<label>Altura <input ng-model="altura"/> m</label><br/>
<button ng-click="calculaImc()">Calcular IMC</button>
<div ng-show="exibeResultados">
<hr/>
<div>IMC: {{ imc | number }}</div>
<div>Situação: {{ situacao }}</div>
</div>
<script>
angular.module('imcApp', [])
.controller('ImcController', function ($scope) {
$scope.calculaImc = function () {
$scope.imc = $scope.peso / ( $scope.altura * $scope.altura );
if ($scope.imc < 18.5) {
$scope.situacao = 'Abaixo do peso';
} else if ($scope.imc >= 18.5 && $scope.imc < 30) {
$scope.situacao = 'Peso normal';
} else if ($scope.imc >= 30) {
$scope.situacao = 'Obesidade';
}
$scope.exibeResultados = true;
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment