I am trying to develop a function that can calculate the total value of a specific property retrieved from a JSON web service.
Here is my function:
$scope.exportData = data;
$scope.totalLW = function() {
$scope.total=0;
for (var i = 0; i < $scope.exportData.result.merchMetrics.SALES_AMOUNT_LW.length; i++) {
$scope.total += parseFloat($scope.exportData.result.merchMetrics.SALES_AMOUNT_LW);
}
return $scope.total;
}
I am calling this function in my HTML view like this:
<td ng-class = "{'positive':totalLW() >= 0, 'negative': totalLW()}">{{totalLW()}}</td>
However, I am encountering an undefined
error in my view. I suspect there might be an issue with my function implementation and need assistance in identifying the problem.
The variable $scope.exportData
seems to be functioning properly as the table binding is working correctly.
Attached below is a screenshot: