2016-10-08 20 views
0

角度のあるテーブルで繰り返しアイテムの合計を計算しようとしています。私はこの問題はされている各項目ごとの小計を取得しますが、すべての項目の集大成を取得してまとめることができるよangularjsを持つ繰り返しアイテムの合計を小計

.controller('reciept_ctrl',['$scope','$http','$state','$stateParams','$window',function($scope,$http,$state,$stateParams,$window){ 
    $scope.shop_id=localStorage.getItem("shop_id"); 
    $scope.payment_id=localStorage.getItem("payment_id"); 
    $http.get('http://localhost/sales/reciept.php?payment_id='+$stateParams.payment_id + "&shop_id="+$scope.shop_id).success(function(data){ 
     console.log(JSON.stringify(data)); 
     $scope.reciept=data; 

     }); 

あなたは壮大を計算する機能を持つことができ

<div ng-repeat="item in reciept"> 
     <table width="100%" border="0" cellspacing="4" cellpadding="4"> 
      <tr> 
      <td width="50%"><div align="left">{{item.item}}</div></td> 
      <td width="16%"><div align="center">{{item.price}}</div></td> 
      <td width="12%"><div align="center">{{item.quantity}}</div></td> 
      <td width="20%"><div align="center">GH¢ {{item.quantity*item.price}}</div></td> 
      </tr> 
      <tr> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
      <td colspan="2">&nbsp;</td> 
      </tr> 
     </table> 
     <p> 

     </div> 

<table width="100%" border="0" cellspacing="1" cellpadding="1"> 
    <tr> 
    <td>Grand Total:</td> 
    </tr> 
</table> 
+0

を置くあなたの代わりにJSのマークアップにサイズを計算しなければならないことあらゆる必要がありますか? – Siddharth

答えて

0

HTML合計、

$scope.getTotal = function(type) { 
     var total = 0; 
     angular.forEach($scope.items, function(el) { 
      total += el[type]; 
     }); 
     return total; 
    }; 

DEMO

0

あなたは合計値を初期化することができます以下のような

<td width="16%" ng-init="total=total+item.price"><div align="center">{{item.price}}</div></td> 

とあなたの総計では、ちょうど

<td>Grand Total:{{total}}</td> 
関連する問題