0
I wonder what’s going wrong because when I do the ng-click
in HTML the {{resultado}}
appears as Nan.
HTML
<button class="button button-full button-positive" ngclick="juntarTotal()">
Juntar os dois campos
</button>
<h3>{{resultado}}</h3>
controller js.
angular.module('app.controllers', [])
.controller('doisnumerosController', function($scope){
$scope.juntarTotal = () => {
$scope.resultado = $scope.valor1 + $scope.valor2;
}
});
First show the values of
$scope.valor1
and value2, see if it has value and if they are numerical. If necessary convert to numbers to sum, exampleNumber($scope.valor1)
– Ricardo Pontual
What does Nan mean in javascript?
– NoobSaibot
My input is "number".
$scope.juntarTotal = () => { 
$scope.resultado = Number($scope.valor1) + Number($scope.valor2;) }
@Ricardopunctual, type like this?– tfarCmiduP
This, to ensure that values are summed up as numbers
– Ricardo Pontual
But it’s not giving, the value of {{result}} in html continues giving Nan, can help me with some example @Ricardopunctual?
– tfarCmiduP
Nan means it is not a number (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN)
– Ricardo Pontual
It means one of your values is not number, you need to see what it is.. in the example you put, the semicolon is inside the parentheses of Function which gives error:
Number($scope.valor2;)
if you used so in the code gives error, the correct isNumber($scope.valor2);
– Ricardo Pontual