Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 46c9c94

Browse files
pomerantsevrodyhaddad
authored andcommitted
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
1 parent 2ad439d commit 46c9c94

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/ng/rootScope.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,17 @@ function $RootScopeProvider(){
261261
expect(scope.counter).toEqual(0);
262262
263263
scope.$digest();
264-
// no variable change
265-
expect(scope.counter).toEqual(0);
264+
// the listener is always called during the first $digest loop after it was registered
265+
expect(scope.counter).toEqual(1);
266266
267-
scope.name = 'adam';
268267
scope.$digest();
268+
// but now it will not be called unless the value changes
269269
expect(scope.counter).toEqual(1);
270270
271+
scope.name = 'adam';
272+
scope.$digest();
273+
expect(scope.counter).toEqual(2);
274+
271275
272276
273277
// Using a listener function
@@ -574,12 +578,16 @@ function $RootScopeProvider(){
574578
expect(scope.counter).toEqual(0);
575579
576580
scope.$digest();
577-
// no variable change
578-
expect(scope.counter).toEqual(0);
581+
// the listener is always called during the first $digest loop after it was registered
582+
expect(scope.counter).toEqual(1);
579583
580-
scope.name = 'adam';
581584
scope.$digest();
585+
// but now it will not be called unless the value changes
582586
expect(scope.counter).toEqual(1);
587+
588+
scope.name = 'adam';
589+
scope.$digest();
590+
expect(scope.counter).toEqual(2);
583591
* ```
584592
*
585593
*/

0 commit comments

Comments
 (0)