0

I am getting the data from my web service and storing the same data into my scope variable like

then(function (Tlist) {
                    $scope.Tlist=Tlist.data;
                })

and displaying the same data into table, now in my table i am selecting the row by checkbox like

                    <td>
                        <input type="checkbox" ng-checked="checkall" ng-model="Ldata.checked" data-ng-click="calculateTotal(Ldata)" />
                    </td>

and in my "calculateTotal(Ldata)" function i want to store the value of (Ldata.amount) into another $scope variable

this is how my condition inside the function looks

        if (Ldata.checked) {
            $scope.total += Number(Ldata.amount);
            console.log(Ldata.amount);
            console.log(Number($scope.total));
        }

but on

console.log(Number($scope.total));

line my result is coming as NaN but on this line and on console.log(Ldata.amount); this line my result is coming as 1400 so i am not able to understand why i am unable to pass data from one variable to another

3
  • it's not really clear what you are asking here. what does the first code snippet have to do with the rest of the question? What is in $scope.total when you start here? What does console.log($scope.total); output? It seems like $scope.total isn't a legal number... Commented Aug 19, 2017 at 3:03
  • 2
    The title of the question is misleading, since this doesn't really appear to have anything at all to do with "passing the data in $scope variable"..... Commented Aug 19, 2017 at 3:04
  • please edit your question and be more specific so that we can go through solution. Commented Aug 19, 2017 at 3:53

2 Answers 2

1

You receive NaN probably because the $scope.total is undefined. If you really want to use += operator you need to know two things:

  • a += b is a shortcut of a = a + b
  • any math operation on number value and undefined will return NaN value

Just set the initial value to $scope.total - for example at the beginning of your controller definition set $scope.total = 0;.

Sign up to request clarification or add additional context in comments.

Comments

0

Instead of Number use parseInt

 console.log(parseInt($scope.total));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.