Skip to content

Commit 7a9d245

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 angular#7598
1 parent 0dbec22 commit 7a9d245

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
@@ -632,12 +636,16 @@ function $RootScopeProvider(){
632636
expect(scope.counter).toEqual(0);
633637
634638
scope.$digest();
635-
// no variable change
636-
expect(scope.counter).toEqual(0);
639+
// the listener is always called during the first $digest loop after it was registered
640+
expect(scope.counter).toEqual(1);
637641
638-
scope.name = 'adam';
639642
scope.$digest();
643+
// but now it will not be called unless the value changes
640644
expect(scope.counter).toEqual(1);
645+
646+
scope.name = 'adam';
647+
scope.$digest();
648+
expect(scope.counter).toEqual(2);
641649
* ```
642650
*
643651
*/

0 commit comments

Comments
 (0)