Q:

calculate total outside ng-repeat

I am trying to calculate total outise ng-repeat which is dependent on ng-change inside ng-repeat. 
My table looks like this
<table>
    <tr>
        <td>Total - total is {{tot}}</td>
    </tr>

    <tr ng-repeat="obj in Array">
         <td>
            <input ng-change="getValue(obj.Cost);" ng-model="obj.Quantity" type="number">
         </td>
        <td>
            <span ng-model="obj.ListPrice">{{obj.ListPrice}}</span>
        </td>
        <td> 
            <input type="number" ng-value="obj.Cost = obj.Quantity * obj.ListPrice">
        </td>
    </tr>
</table>

Now i am calculating total 
var total = 0;
$scope.getValue = function(Cost){
    total += parseInt(Cost);
    $scope.tot = total
}   

which is not happening. What is the right way to do it?

A:

You can access the total outside ng-repeat like this
<span>Total is - {{total}}</span>    
<table>
    <tbody ng-init="total = 0">
    <tr ng-repeat="obj in Array">
         <td>
            <input ng-change="getValue(obj.Cost);" ng-model="obj.Quantity" type="number">
         </td>
        <td>
            <span ng-model="obj.ListPrice">{{obj.ListPrice}}</span>
        </td>
        <td ng-init="$parent.total = $parent.total + (obj.Quantity * obj.ListPrice)"> 
            <input type="number" ng-value="obj.Cost = obj.Quantity * obj.ListPrice">
        </td>
    </tr>
</table>

Basically you are doing sum inside ng-repeat and doing ng-init in tbody, so that u can access the total outside ng-repeat

