Reputation:
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
Upvotes: 0
Views: 67
Reputation: 98
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
undefined
will return NaN
valueJust set the initial value to $scope.total
- for example at the beginning of your controller definition set $scope.total = 0;
.
Upvotes: 1
Reputation: 222582
Instead of Number
use parseInt
console.log(parseInt($scope.total));
Upvotes: 0