From 46c9c942df8cd06875536dfb57a56b75c4d5037c Mon Sep 17 00:00:00 2001 From: Pavel Pomerantsev Date: Sun, 25 May 2014 11:53:28 +0400 Subject: [PATCH] docs($rootScope): fix incorrect docs and make them clearer During the first $digest loop after registering a $watch the listener always run, so the example was incorrect Closes #7598 --- src/ng/rootScope.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 76b8d08f0..b61c79b7f 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -261,12 +261,16 @@ function $RootScopeProvider(){ expect(scope.counter).toEqual(0); scope.$digest(); - // no variable change - expect(scope.counter).toEqual(0); + // the listener is always called during the first $digest loop after it was registered + expect(scope.counter).toEqual(1); + + scope.$digest(); + // but now it will not be called unless the value changes + expect(scope.counter).toEqual(1); scope.name = 'adam'; scope.$digest(); - expect(scope.counter).toEqual(1); + expect(scope.counter).toEqual(2); @@ -574,12 +578,16 @@ function $RootScopeProvider(){ expect(scope.counter).toEqual(0); scope.$digest(); - // no variable change - expect(scope.counter).toEqual(0); + // the listener is always called during the first $digest loop after it was registered + expect(scope.counter).toEqual(1); + + scope.$digest(); + // but now it will not be called unless the value changes + expect(scope.counter).toEqual(1); scope.name = 'adam'; scope.$digest(); - expect(scope.counter).toEqual(1); + expect(scope.counter).toEqual(2); * ``` * */