javascript - Parsing integers in AngularJS -


i using angularjs in 1 of our application.

in code below, while loading page expression addition (number, valuetoadd) parses correctly , give output 1+1=2 while changing input doesn't parse correctly , gives output `1+2=12'.

where need change?

<div ng-controller='mathscontroller'>     <input type="range" min="0" max="100" step="1" value="1" ng-model='valuetoadd'/>      <p>addition table of <b>{{valuetoadd}}</b></p>      <div ng-repeat='number in numbers'>         {{number}} + {{valuetoadd}} = {{ addition(number,valuetoadd) }}     </div> </div> <script type="text/javascript">     function mathscontroller($scope)      {         $scope.valuetoadd= 1;         $scope.numbers =[1,2,3,4,5,6,7,8,9,10];          $scope.addition = function(number,valuetoadd)         {             return number+valuetoadd;         }     } </script> 

may number beging passed string. try:

        $scope.addition = function(number, multiplier)         {             return + number + multiplier;         } 

+ convert string number.

edit: now, see multiplier passed string. has converted instead...

sorry did not read code carefully.

        $scope.addition = function(number, multiplier)         {             return number + +multiplier;         } 

thank @artur pointing out.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -