Created
November 14, 2016 18:00
-
-
Save alexandreaquiles/a14a8f73081c9c097826b3e55e2f601a to your computer and use it in GitHub Desktop.
Cálculo de IMC com Angular usando MVC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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