Skip to content

Instantly share code, notes, and snippets.

@leosilvadev
Last active February 13, 2016 11:04
Show Gist options
  • Save leosilvadev/e513c21f3b967c8ccc3a to your computer and use it in GitHub Desktop.
Save leosilvadev/e513c21f3b967c8ccc3a to your computer and use it in GitHub Desktop.
<DOCTYPE html>
<html ng-app="contador">
<head>
<style>
@IMPORT url("bootstrap-3.3.6-dist/css/bootstrap.min.css");
</style>
</head>
<body>
<div class="container">
<div class="row" ng-controller="ContadorController" ng-init="calcula()">
<div class="well col-sm-4">
<input ng-model="numero1" type="number" ng-change="calcula()" class="form-control">
</div>
<div class="well col-sm-4">
<input ng-model="numero2" type="number" ng-change="calcula()" class="form-control">
</div>
<div class="well col-sm-4">
<select ng-model="operacao" ng-options="op.texto for op in operacoesDisponiveis track by op.val" ng-change="calcula()" class="form-control"></select>
</div>
<div class="well col-sm-12" style="text-align:center;">
<h1 ng-bind="resultado"></h1>
</div>
</div>
</div>
<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 = {texto:'Soma', val:'+'};
$scope.operacoesDisponiveis = [
{texto:'Soma', val:'+'},
{texto:'Subtracao', val:'-'},
{texto:'Multiplicacao', val:'*'},
{texto:'Divisao', val:'/'}
];
$scope.calcula = function(){
$scope.resultado = eval($scope.numero1 + $scope.operacao.val + $scope.numero2);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment