title: angularjs service is not a function
body: <p>I have a service like so:</p>
  
  <pre><code>app.service('Utilities', function() {
    this.sum = function(items, prop) {
      var count, total;
      total = 0;
      count = 0;
      if (items === null) {
        total = 0;
      }
      while (count &lt; items.length) {
        total += items[count][prop] * 1 || 0;
        count++;
      }
      return total;
    };
  });
  </code></pre>
  
  <p>and a controller like so:</p>
  
  <pre><code>app.controller('writeCtrl', function($scope, Utilities, students) {
    $scope.students = students;
    $scope.total_age = Utilities.sum($scope.students, 'age');
  });
  </code></pre>
  
  <p>And I keep getting the error </p>
  
  <blockquote>
    <p>Typerror: Utilities.sum is not a function</p>
  </blockquote>
  
  <p>Which is confusing because about a dozen other functions under the Utilities service is working fine. What's causing the issue, and how do I get the function to work?</p>
  
  <p><strong>Edit</strong>
  Actual Coffeescript version</p>
  
  <pre><code>app.service 'Utilities', -&gt;
    @sum = (items, prop) -&gt;
      total = 0
      count = 0
      if items == null
        total = 0
      while count &lt; items.length
        total += (items[count][prop]*1 || 0)
        count++
      return total
  
  app.controller 'writeCtrl', ($scope, Utilities, students) -&gt;
    $scope.students = students
    $scope.total_age = Utilities.sum($scope.students, 'age')
  </code></pre>
  
  <p><strong>Solution:</strong></p>
  
  <p>Coffeescript functions need a return:</p>
  
  <pre><code>App.service 'Utilities', -&gt; 
    .....
    return
  </code></pre>