Now there's a really cool trick to actually kind of tie in,
into the digest loop and to see when it's actually getting executed.
So far, all we've seen is how are watch is being executed, but
what about the digest loop.
Well, the way we could do this is the following.
If we say $scope.$watch and now instead of giving it
a real property around our scope, we'll give it a function, because this
function is something that is supposed to return the name of the property to watch.
Which means every time through the loop,
the digest cycle will want to figure out what property is that and execute it.
So that means we could catch when the digest loop
is actually going through all these watchers.
So all we have to do is really provide one function.
And we'll say here, log("Digest Loop Fired!").
Let's save that.
I'm going to go back,
you'll see the digest loop already fired twice before we even started anything.
And the reason that is is that when we go back and look as to what's going on here,
since our watchers are being set up by the interpolation, double curly braces,
when we have the $scope.onceCounter equals zero,
that means this property gets changed and so does this.
So which means there's already a one time that the properties gets changed and
since we know that one time things are changing, it will go once through loop and
it will go through loop one more time just to see that everything is clean,
there's no dirty values, meaning nothing has changed anymore.
That's why you see here the Digest Loop Fired twice.
Now, if we click one up once counter, you'll see that, again, it fired twice.
Because one time was for changing the actual counter, and
another time, to see that nothing's changed.
Now, now that I know that it's changed and it will not change again,
if I click up once counter again you'll see that it's only changing once.
Let's actually clear that and you'll see that the digest loop is only getting fired
once let's clear it again and still only get fired once, and
the reason that is, is that through the first time that a digest loop fires,
it sees that nothing really has changed.
However, if we say Increment Counter, well it's going to fire twice.
Once for checking that the counter actually got incremented and
once to see that nothing else has changed.
If we click it, and we clear that again click it again,
it will once again see that the counter change and then we'll run
through all the watchers once again to see that nothing else has change.
And therefore every time I click, you'll see that the number of times
this console.log will get printed out is going to be incrementing by two,
so six, eight, ten and so on,
in other words every time I click, it's going to be two times of the digest loop
goes through the watchers to make sure that everything us updated properly.