From 7a9d24551fb67d60503be7f31489c76f9d54ce95 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 030e0b05..f4fed509 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); @@ -632,12 +636,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); * ``` * */