title: AngularJS: $watchCollection does not work; throws error
body: <p>I've got a problem in AngularJS where <code>$scope.$watchCollection()</code> throws an error. I've reduced my code to the point where it's exactly the same as example code in the docs (<a href="http://docs.angularjs.org/api/ng" rel="nofollow">http://docs.angularjs.org/api/ng</a>.$rootScope.Scope#$watchCollection), and the error is still thrown:</p>
  
  <pre><code>function OverviewCtrl($scope) {
    $scope.names = ['igor', 'matias', 'misko', 'james'];
    $scope.dataCount = 4;
  
    $scope.$watchCollection('names', function(newNames, oldNames) {
      $scope.dataCount = newNames.length;
    });
  }
  </code></pre>
  
  <p>I get the error </p>
  
  <pre><code>'undefined' is not a function (evaluating '$scope.$watchCollection('names', function(newNames, oldNames) {
    $scope.dataCount = newNames.length;
  })')
  </code></pre>
  
  <p>I have no idea what the problem could possibly be. I'm doing exactly what the docs say, except I'm putting it in a controller, but it seems this code is intended for use in controllers. So what's the problem here?</p>