Skip to content

Instantly share code, notes, and snippets.

@leosilvadev
Created January 10, 2016 01:26
Show Gist options
  • Save leosilvadev/8b2c2cdbd4fc162b3d5e to your computer and use it in GitHub Desktop.
Save leosilvadev/8b2c2cdbd4fc162b3d5e to your computer and use it in GitHub Desktop.
<DOCTYPE html>
<html ng-app="contador">
<head></head>
<body>
<section ng-controller="ContadorController">
<input ng-model="numero1" type="number" ng-change="calcula()">
<input ng-model="numero2" type="number" ng-change="calcula()">
<select ng-model="operacao" ng-options="op for op in operacoesDisponiveis" ng-change="calcula()">
</select>
<span>{{resultado}}</span>
</section>
<script src="angular.min.js"></script>
<script>
angular.module('contador', []);
angular.module('contador').controller('ContadorController', function($scope){
$scope.numero1 = 0;
$scope.numero2 = 0;
$scope.operacao = '+';
$scope.operacoesDisponiveis = ['+', '-', '*', '/'];
$scope.calcula = function(){
$scope.resultado = eval($scope.numero1 + $scope.operacao + $scope.numero2);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment