title: Angular - sum up numbers using a function and put it in the view
body: <p>I am trying to create a function that will sum up some numbers from an incoming factory (and some from the client-side in real time), and will put the sum in the view. Totally stuck. </p>
  
  <p>1 - First of all, I do not understand how to display in the view a variable that was assembled within a controller function. </p>
  
  <p>So let's say I have something like:</p>
  
  <pre><code>$scope.total = function() {
      var totalNumber = 0;
  
  }  
  </code></pre>
  
  <p>How do I get the totalNumber to show in the view?</p>
  
  <p>I assume after I get this, in order to sum up my factory data: </p>
  
  <pre><code>var revenues = [
              { amount: 1254 },
              { amount: 1654 },
              { amount: 33 },
              { amount: 543 }
  
      ];
  </code></pre>
  
  <p>I will have to do something like:</p>
  
  <pre><code> $scope.total = function() {
   var totalNumber = 0;
      for(i=0; i&lt;revenues.length; i++){
        totalNumber = totalNumber + revenues[i].amount
      }
  
      }  
  </code></pre>
  
  <p>Is this correct? Will it update in real time if I dynamically change the revenue array?</p>