I am an angular-noob and I am trying to understand why the following triggers the "$apply is already in progress ..." error.
Here is the code (and its really almost straight from the documentation: https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest)
<!DOCTYPE html>
<html>
<head>
    <script src="js/lib/angular.js"></script>
    <script>
    var app = angular.module('app', []);
    app.controller('MainController', ['$scope', function(scope) {
        scope.name = 'misko';
        scope.counter = 0;
        //A
        scope.$watch('name', function(newValue, oldValue) {
            scope.count++;
        });
        //B
        scope.$digest();
    }]);
    </script>
</head>
<body>
    <div ng-app='app' ng-controller="MainController">
    </div>
</body>
</html>
And, here is the fiddle: https://jsfiddle.net/zLny2faq/5/
I get the in-famous "$apply already in progress" error but why is that ?
I would like to know why the digest cycle triggers without even being called ?
In other words, I am merely declaring watch listeners (@comment A) and triggering them by calling $digest() (@comment B) . But it seems like its somehow being called sooner and errors out when I explicitly called $digest(). Why is this so ?
Please advise.
 
     
     
     
    