In my angular application, I have a function that creates tables using directives. Each field in the tables must have unique ng-model names so that I can calculate each table individually. To achieve this, I implemented a counter that increments with each added table and appends the current count to the end of each ng-model name for every field (you can refer to my plunkr link for more details).
However, I'm facing an issue with my $scope.total function which sums the fields. It works fine with static ng-model names but I'm struggling to concatenate the ng-model names with the current count to ensure the function calculates each table separately when adding a number after each ng-model. How can I modify my $scope.total function to work with dynamic ng-model names?
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.count = 0;
$scope.total = function(count){
var total =
// I want to parseFloat the $scope.td1 + the current count.
// How does the syntax look when you concat ng-model.
parseFloat($scope.td1 + count || 0) +
parseFloat($scope.td2 + count || 0) +
parseFloat($scope.td3 + count || 0) +
parseFloat($scope.td4 + count || 0) +
parseFloat($scope.td5 + count || 0);
return total || 0;
}
});
Edit: I have also added a new input to my plunkr that should display the sum of the "total" in the first two generated tables. However, this functionality is currently not working as expected and I am unable to determine the cause. I introduced a new function to summarize the totals from the first two tables.