title: dynamically calculate sum of values in an array using Angular js
body: <p>I am working on a project called "Gold loan management system".<a href="https://i.stack.imgur.com/z7rCG.png" rel="nofollow noreferrer">Form fields to insert the ornament name and weight.Total number of ornaments and total weight is calculated automatically</a>.I Couldn't calculate the total weight dynamically.Here is my code---</p>
  
  <p><strong>index.html</strong>
       </p>
  
  <pre><code>&lt;fieldset  data-ng-repeat="choice in choices"&gt;
  &lt;div class="form-group"&gt;
  &lt;select class="form-control" name="optioin" ng-model="choice.option" &gt;
  &lt;option value="Ring"&gt;Ring&lt;/option&gt;
  &lt;option value="Earings"&gt;Earings&lt;/option&gt;
   &lt;option value="Chains"&gt;Chains&lt;/option&gt;
   &lt;option value="Necklaces"&gt;Necklaces&lt;/option&gt;
   &lt;option value="Bangles"&gt;Bangles&lt;/option&gt;
   &lt;/select&gt;
   &lt;/div&gt;
   &lt;div class="form-group"&gt;
      &lt;input class="form-control" type="number" ng-model="choice.weight" name=""   placeholder="Enter the weight"&gt;gm
    &lt;button class="btn btn-default" ng-show="$last"  ng-click="removeChoice()   "&gt;&lt;span class="glyphicon glyphicon-minus" aria-hidden="true"&gt;&lt;/span&gt;&lt;/button&gt;
   &lt;button class="btn btn-default"  ng-show="$last" ng-click="addNewChoice()"&gt; &lt;span class="glyphicon glyphicon-plus" aria-hidden="true"&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;/div&gt;    
  
   &lt;/fieldset&gt;
   &lt;/form&gt;
   &lt;form class="form-inline"&gt;
   &lt;div class="form-group"&gt;
   &lt;label for="totnumber"&gt;Total Nos:&lt;/label&gt;
   &lt;input type="number" ng-model="choices.length" class="form-control"      id="totnumber"&gt;
   &lt;/div&gt;
    &lt;div class="form-group"&gt;
   &lt;label for="totweight"&gt;Total Weight:&lt;/label&gt;
   &lt;input type="number"   ng-model="total" class="form-control" id="totweight"&gt;
   &lt;/div&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p><strong>dashboardcntrl.js</strong></p>
  
  <pre><code>  app.controller('dashboardCtrl', function($scope) {
    $scope.choices = [{id: 'choice1'}];
    $scope.addNewChoice = function() {
              var newItemNo = $scope.choices.length+1;
              $scope.choices.push({'id':'choice'+newItemNo});
               console.log(   $scope. choices.length );
  
            };
  
    $scope.removeChoice = function() {
              var lastItem = $scope.choices.length-1;
              $scope.choices.splice(lastItem);
                   console.log(   $scope. choices.length );
            };
          });  
  </code></pre>
  
  <p>How can i do that?</p>