Created
January 27, 2019 04:44
-
-
Save johncab1/9d70c4dd139286f422b524f7ab2f6f50 to your computer and use it in GitHub Desktop.
Suma en angular con evento click
This file contains 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
angular.module("MiApp",[]).controller("miControlador", | |
function($scope) | |
{ | |
$scope.numero1 = ""; | |
$scope.numero2 = ""; | |
$scope.resultado = ""; | |
$scope.sumar = function() | |
{ | |
$scope.resultado = ($scope.numero1 * 1) + ($scope.numero2 * 1); | |
} | |
} | |
); |
This file contains 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="MiApp"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Suma con angular</title> | |
<script src="angular.min.js"></script> | |
<script src="controlador.js"></script> | |
</head> | |
<body ng-controller="miControlador"> | |
<label>Numero 1</label><input type="text" ng-model="numero1"><br> | |
<label>Numero 2</label><input type="text" ng-model="numero2"><br> | |
<button ng-click="sumar()">Sumar</button> | |
<h3>Resultado: </h3> <h2>{{ resultado }}</h2> | |
</body> | |
</html> |
hola, cómo haces para sumar? creo realizar el mismo proceso y en vez de sumar se concatenan las variables
Puedes multiplicar las variables por 1 para que javascript las tome como enteros o puedes usar la función parseInt ()
Muchas gracias, buscaba una forma sin usar el parseInt y me resultó la de multiplicar las variables por 1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Puedes multiplicar las variables por 1 para que javascript las tome como enteros o puedes usar la función parseInt()