JSFiddle - React, Tailwind, and code Playground

by Anthony Price

HTML

<script src="https://code.angularjs.org/1.2.16/angular.min.js"></script>
<div ng-controller="MainCtrl">
    <div class="form-control2" ng-repeat="row in rows">
        <input type="number" class="form-control" ng-model="row.unit_price" ng-change="setTotals()"/>{{row.mytotal}}
      
       
    <br />
    </div>
    <div style="padding-top:20px;">Total of all rows: {{total | currency:'€'}}</div>
    
</div>

CSS

.form-control2 {padding-top:20px;}

JavaScript

var app = angular.module('myApp', []);

app.controller('MainCtrl', function ($scope) {
    $scope.rows = [{
        unit_price: 1,
        quantity: 0,
        flag: false,
      group: 1
    }, {
        unit_price: 2,
     
      flag: false,
      group: 1
    },
                   {
        unit_price: null,
        mytotal: 'total',
      flag: true,
      group: 1
    },
                   {
        unit_price: 7,
      flag: false,
      group: 2
    },
                       {
        unit_price: 4,
      flag: false,
      group: 2
    },
    {
        unit_price: 0,
      flag: true,
        mytotal: 'total',
      group: 2
    },
         {
        unit_price: 0,
      flag: true,
        mytotal: 'total',
      group: 3
    },
         {
        unit_price: 1,
      flag: true,
        mytotal: 'total',
      group: 4
    }
   
    ];
  $scope.showtotal =  function () 
  {
  
  }
  $scope.setTotals = function()
  {
    var sum = 0;
    $scope.total = 0;
  	angular.forEach($scope.rows, function(row){
      if (row.flag) {
        row.unit_price = sum;
        $scope.total += sum;
        sum = 0;
      }
      else {
        sum += row.unit_price;
      }
    })
  }
  $scope.setTotals();
  /*
    $scope.$watch('rows', function () {
        $scope.total = 0
        angular.forEach($scope.rows, function(row){
            $scope.total += row.unit_price * 1
        })
    }, true) */
});