I am creating group of inputs elements dynamically in angularJs. I want to find total, Controller,
$scope.itemElements = [
{
"item": "item1",
"quantity": 2,
"rate": 12.5
},
{
"item": "item2",
"quantity": 2,
"rate": 12.5
},
{
"item": "item3",
"quantity": 2,
"rate": 12.5
}
];
$scope.calculateSum = function ()
{
var sum = 0;
for (var i = 0; i < $scope.itemElements.length; i++)
{
sum += $scope.itemElements["quantity"];
}
return sum;
}
HTML,
<tr ng-repeat="itemElemen in itemElements">
<td><input type="text" class="form-control" ng-model="itemElemen.item" placeholder="Enter item" list="clientList"/></td>
<td><input type="text" class="form-control" ng-model="itemElemen.quantity" placeholder="Quantity"/></td>
<td><input type="text" class="form-control" ng-model="itemElemen.rate" placeholder="Rate"/></td>
<td><input type="text" class="form-control" placeholder="Amount" ng-value="itemElemen.quantity*itemElemen.rate"/></td>
</tr>
Totatl,
Total <span id="totalSum" ng-model="calculateSum()"></span>
It is not working,getting error is [ngModel:nonassign], How can I do the same?