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

Commit a8aa193

Browse files
committed
doc($rootScope): scope documentation changes
1 parent e45b013 commit a8aa193

File tree

1 file changed

+77
-51
lines changed

1 file changed

+77
-51
lines changed

src/service/scope.js

+77-51
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,33 @@
2424
* implemented in the same way as watch. Watch requires return of initialization function which
2525
* are expensive to construct.
2626
*/
27+
28+
/**
29+
* @ngdoc object
30+
* @name angular.module.NG.$rootScope
31+
* @description
32+
*
33+
* Every application has a single root {@link angular.model.NG.$rootScope.Scope scope}.
34+
* All other scopes are child scopes of the root scope. Scopes provide mechanism for watching the model and provide
35+
* event processing life-cycle. See {@link guide/dev_guide.scopes developer guide on scopes}.
36+
*/
2737
function $RootScopeProvider(){
2838
this.$get = ['$injector', '$exceptionHandler', '$parse',
2939
function( $injector, $exceptionHandler, $parse){
3040
/**
3141
* @ngdoc function
32-
* @name angular.scope
42+
* @name angular.module.NG.$rootScope.Scope
3343
*
3444
* @description
35-
* A root scope can be created by calling {@link angular.scope angular.scope()}. Child scopes
36-
* are created using the {@link angular.scope.$new $new()} method.
37-
* (Most scopes are created automatically when compiled HTML template is executed.)
45+
* A root scope can be retrieved using the {@link angular.module.NG.$rootScope $rootScope} key from the
46+
* {@link angular.model.AUTO.$injector $injector}. Child scopes are created using the
47+
* {@link angular.module.NG.$rootScope.Scope.$new $new()} method. (Most scopes are created automatically when
48+
* compiled HTML template is executed.)
3849
*
3950
* Here is a simple scope snippet to show how you can interact with the scope.
4051
* <pre>
41-
var scope = angular.scope();
52+
angular.injector(function($rootScope) {
53+
var scope = $rootScope.$new();
4254
scope.salutation = 'Hello';
4355
scope.name = 'World';
4456
@@ -55,12 +67,13 @@ function $RootScopeProvider(){
5567
5668
scope.$digest(); // fire all the watches
5769
expect(scope.greeting).toEqual('Hello Misko!');
70+
});
5871
* </pre>
5972
*
6073
* # Inheritance
6174
* A scope can inherit from a parent scope, as in this example:
6275
* <pre>
63-
var parent = angular.scope();
76+
var parent = $rootScope;
6477
var child = parent.$new();
6578
6679
parent.salutation = "Hello";
@@ -97,7 +110,8 @@ function $RootScopeProvider(){
97110

98111
/**
99112
* @ngdoc property
100-
* @name angular.scope.$id
113+
* @name angular.module.NG.$rootScope.Scope#$id
114+
* @propertyOf angular.module.NG.$rootScope.Scope
101115
* @returns {number} Unique scope ID (monotonically increasing alphanumeric sequence) useful for
102116
* debugging.
103117
*/
@@ -106,16 +120,17 @@ function $RootScopeProvider(){
106120
Scope.prototype = {
107121
/**
108122
* @ngdoc function
109-
* @name angular.scope.$new
123+
* @name angular.module.NG.$rootScope.Scope#$new
124+
* @methodOf angular.module.NG.$rootScope.Scope
110125
* @function
111126
*
112127
* @description
113-
* Creates a new child {@link angular.scope scope}. The new scope can optionally behave as a
114-
* controller. The parent scope will propagate the {@link angular.scope.$digest $digest()} and
115-
* {@link angular.scope.$digest $digest()} events. The scope can be removed from the scope
116-
* hierarchy using {@link angular.scope.$destroy $destroy()}.
128+
* Creates a new child {@link angular.module.NG.$rootScope.Scope scope}. The new scope can optionally behave as a
129+
* controller. The parent scope will propagate the {@link angular.module.NG.$rootScope.Scope.$digest $digest()} and
130+
* {@link angular.module.NG.$rootScope.Scope.$digest $digest()} events. The scope can be removed from the scope
131+
* hierarchy using {@link angular.module.NG.$rootScope.Scope.$destroy $destroy()}.
117132
*
118-
* {@link angular.scope.$destroy $destroy()} must be called on a scope when it is desired for
133+
* {@link angular.module.NG.$rootScope.Scope.$destroy $destroy()} must be called on a scope when it is desired for
119134
* the scope and its child scopes to be permanently detached from the parent and thus stop
120135
* participating in model change detection and listener notification by invoking.
121136
*
@@ -160,16 +175,17 @@ function $RootScopeProvider(){
160175

161176
/**
162177
* @ngdoc function
163-
* @name angular.scope.$watch
178+
* @name angular.module.NG.$rootScope.Scope#$watch
179+
* @methodOf angular.module.NG.$rootScope.Scope
164180
* @function
165181
*
166182
* @description
167183
* Registers a `listener` callback to be executed whenever the `watchExpression` changes.
168184
*
169-
* - The `watchExpression` is called on every call to {@link angular.scope.$digest $digest()} and
170-
* should return the value which will be watched. (Since {@link angular.scope.$digest $digest()}
185+
* - The `watchExpression` is called on every call to {@link angular.module.NG.$rootScope.Scope.$digest $digest()} and
186+
* should return the value which will be watched. (Since {@link angular.module.NG.$rootScope.Scope.$digest $digest()}
171187
* reruns when it detects changes the `watchExpression` can execute multiple times per
172-
* {@link angular.scope.$digest $digest()} and should be idempotent.)
188+
* {@link angular.module.NG.$rootScope.Scope.$digest $digest()} and should be idempotent.)
173189
* - The `listener` is called only when the value from the current `watchExpression` and the
174190
* previous call to `watchExpression' are not equal. The inequality is determined according to
175191
* {@link angular.equals} function. To save the value of the object for later comparison
@@ -180,15 +196,15 @@ function $RootScopeProvider(){
180196
* limit is 100 to prevent infinity loop deadlock.
181197
*
182198
*
183-
* If you want to be notified whenever {@link angular.scope.$digest $digest} is called,
199+
* If you want to be notified whenever {@link angular.module.NG.$rootScope.Scope.$digest $digest} is called,
184200
* you can register an `watchExpression` function with no `listener`. (Since `watchExpression`,
185-
* can execute multiple times per {@link angular.scope.$digest $digest} cycle when a change is
201+
* can execute multiple times per {@link angular.module.NG.$rootScope.Scope.$digest $digest} cycle when a change is
186202
* detected, be prepared for multiple calls to your listener.)
187203
*
188204
*
189205
* # Example
190206
<pre>
191-
var scope = angular.scope();
207+
var scope = angular.module.NG.$rootScope.Scope();
192208
scope.name = 'misko';
193209
scope.counter = 0;
194210
@@ -208,7 +224,7 @@ function $RootScopeProvider(){
208224
*
209225
*
210226
* @param {(function()|string)} watchExpression Expression that is evaluated on each
211-
* {@link angular.scope.$digest $digest} cycle. A change in the return value triggers a
227+
* {@link angular.module.NG.$rootScope.Scope.$digest $digest} cycle. A change in the return value triggers a
212228
* call to the `listener`.
213229
*
214230
* - `string`: Evaluated as {@link guide/dev_guide.expressions expression}
@@ -247,36 +263,39 @@ function $RootScopeProvider(){
247263

248264
/**
249265
* @ngdoc function
250-
* @name angular.scope.$digest
266+
* @name angular.module.NG.$rootScope.Scope#$digest
267+
* @methodOf angular.module.NG.$rootScope.Scope
251268
* @function
252269
*
253270
* @description
254-
* Process all of the {@link angular.scope.$watch watchers} of the current scope and its children.
255-
* Because a {@link angular.scope.$watch watcher}'s listener can change the model, the
256-
* `$digest()` keeps calling the {@link angular.scope.$watch watchers} until no more listeners are
271+
* Process all of the {@link angular.module.NG.$rootScope.Scope.$watch watchers} of the current scope and its children.
272+
* Because a {@link angular.module.NG.$rootScope.Scope.$watch watcher}'s listener can change the model, the
273+
* `$digest()` keeps calling the {@link angular.module.NG.$rootScope.Scope.$watch watchers} until no more listeners are
257274
* firing. This means that it is possible to get into an infinite loop. This function will throw
258275
* `'Maximum iteration limit exceeded.'` if the number of iterations exceeds 100.
259276
*
260277
* Usually you don't call `$digest()` directly in
261278
* {@link angular.directive.ng:controller controllers} or in {@link angular.directive directives}.
262-
* Instead a call to {@link angular.scope.$apply $apply()} (typically from within a
279+
* Instead a call to {@link angular.module.NG.$rootScope.Scope.$apply $apply()} (typically from within a
263280
* {@link angular.directive directive}) will force a `$digest()`.
264281
*
265282
* If you want to be notified whenever `$digest()` is called,
266-
* you can register a `watchExpression` function with {@link angular.scope.$watch $watch()}
283+
* you can register a `watchExpression` function with {@link angular.module.NG.$rootScope.Scope.$watch $watch()}
267284
* with no `listener`.
268285
*
269286
* You may have a need to call `$digest()` from within unit-tests, to simulate the scope
270287
* life-cycle.
271288
*
272289
* # Example
273290
<pre>
274-
var scope = angular.scope();
291+
var scope = ...;
275292
scope.name = 'misko';
276293
scope.counter = 0;
277294
278295
expect(scope.counter).toEqual(0);
279-
scope.$digest('name', function(scope, newValue, oldValue) { counter = counter + 1; });
296+
scope.$digest('name', function(scope, newValue, oldValue) {
297+
counter = counter + 1;
298+
});
280299
expect(scope.counter).toEqual(0);
281300
282301
scope.$digest();
@@ -363,16 +382,17 @@ function $RootScopeProvider(){
363382

364383
/**
365384
* @ngdoc function
366-
* @name angular.scope.$destroy
385+
* @name angular.module.NG.$rootScope.Scope#$destroy
386+
* @methodOf angular.module.NG.$rootScope.Scope
367387
* @function
368388
*
369389
* @description
370390
* Remove the current scope (and all of its children) from the parent scope. Removal implies
371-
* that calls to {@link angular.scope.$digest $digest()} will no longer propagate to the current
391+
* that calls to {@link angular.module.NG.$rootScope.Scope.$digest $digest()} will no longer propagate to the current
372392
* scope and its children. Removal also implies that the current scope is eligible for garbage
373393
* collection.
374394
*
375-
* The destructing scope emits an `$destroy` {@link angular.scope.$emit event}.
395+
* The destructing scope emits an `$destroy` {@link angular.module.NG.$rootScope.Scope.$emit event}.
376396
*
377397
* The `$destroy()` is usually used by directives such as
378398
* {@link angular.widget.@ng:repeat ng:repeat} for managing the unrolling of the loop.
@@ -391,7 +411,8 @@ function $RootScopeProvider(){
391411

392412
/**
393413
* @ngdoc function
394-
* @name angular.scope.$eval
414+
* @name angular.module.NG.$rootScope.Scope#$eval
415+
* @methodOf angular.module.NG.$rootScope.Scope
395416
* @function
396417
*
397418
* @description
@@ -400,7 +421,7 @@ function $RootScopeProvider(){
400421
*
401422
* # Example
402423
<pre>
403-
var scope = angular.scope();
424+
var scope = angular.module.NG.$rootScope.Scope();
404425
scope.a = 1;
405426
scope.b = 2;
406427
@@ -421,7 +442,8 @@ function $RootScopeProvider(){
421442

422443
/**
423444
* @ngdoc function
424-
* @name angular.scope.$evalAsync
445+
* @name angular.module.NG.$rootScope.Scope#$evalAsync
446+
* @methodOf angular.module.NG.$rootScope.Scope
425447
* @function
426448
*
427449
* @description
@@ -430,7 +452,7 @@ function $RootScopeProvider(){
430452
* The `$evalAsync` makes no guarantees as to when the `expression` will be executed, only that:
431453
*
432454
* - it will execute in the current script execution context (before any DOM rendering).
433-
* - at least one {@link angular.scope.$digest $digest cycle} will be performed after
455+
* - at least one {@link angular.module.NG.$rootScope.Scope.$digest $digest cycle} will be performed after
434456
* `expression` execution.
435457
*
436458
* Any exceptions from the execution of the expression are forwarded to the
@@ -448,15 +470,16 @@ function $RootScopeProvider(){
448470

449471
/**
450472
* @ngdoc function
451-
* @name angular.scope.$apply
473+
* @name angular.module.NG.$rootScope.Scope#$apply
474+
* @methodOf angular.module.NG.$rootScope.Scope
452475
* @function
453476
*
454477
* @description
455478
* `$apply()` is used to execute an expression in angular from outside of the angular framework.
456479
* (For example from browser DOM events, setTimeout, XHR or third party libraries).
457480
* Because we are calling into the angular framework we need to perform proper scope life-cycle
458481
* of {@link angular.service.$exceptionHandler exception handling},
459-
* {@link angular.scope.$digest executing watches}.
482+
* {@link angular.module.NG.$rootScope.Scope.$digest executing watches}.
460483
*
461484
* ## Life cycle
462485
*
@@ -475,11 +498,11 @@ function $RootScopeProvider(){
475498
* Scope's `$apply()` method transitions through the following stages:
476499
*
477500
* 1. The {@link guide/dev_guide.expressions expression} is executed using the
478-
* {@link angular.scope.$eval $eval()} method.
501+
* {@link angular.module.NG.$rootScope.Scope.$eval $eval()} method.
479502
* 2. Any exceptions from the execution of the expression are forwarded to the
480503
* {@link angular.service.$exceptionHandler $exceptionHandler} service.
481-
* 3. The {@link angular.scope.$watch watch} listeners are fired immediately after the expression
482-
* was executed using the {@link angular.scope.$digest $digest()} method.
504+
* 3. The {@link angular.module.NG.$rootScope.Scope.$watch watch} listeners are fired immediately after the expression
505+
* was executed using the {@link angular.module.NG.$rootScope.Scope.$digest $digest()} method.
483506
*
484507
*
485508
* @param {(string|function())=} exp An angular expression to be executed.
@@ -501,11 +524,12 @@ function $RootScopeProvider(){
501524

502525
/**
503526
* @ngdoc function
504-
* @name angular.scope.$on
527+
* @name angular.module.NG.$rootScope.Scope#$on
528+
* @methodOf angular.module.NG.$rootScope.Scope
505529
* @function
506530
*
507531
* @description
508-
* Listen on events of a given type. See {@link angular.scope.$emit $emit} for discussion of
532+
* Listen on events of a given type. See {@link angular.module.NG.$rootScope.Scope.$emit $emit} for discussion of
509533
* event life cycle.
510534
*
511535
* @param {string} name Event name to listen on.
@@ -535,19 +559,20 @@ function $RootScopeProvider(){
535559

536560
/**
537561
* @ngdoc function
538-
* @name angular.scope.$emit
562+
* @name angular.module.NG.$rootScope.Scope#$emit
563+
* @methodOf angular.module.NG.$rootScope.Scope
539564
* @function
540565
*
541566
* @description
542567
* Dispatches an event `name` upwards through the scope hierarchy notifying the
543-
* registered {@link angular.scope.$on} listeners.
568+
* registered {@link angular.module.NG.$rootScope.Scope.$on} listeners.
544569
*
545570
* The event life cycle starts at the scope on which `$emit` was called. All
546-
* {@link angular.scope.$on listeners} listening for `name` event on this scope get notified.
571+
* {@link angular.module.NG.$rootScope.Scope.$on listeners} listening for `name` event on this scope get notified.
547572
* Afterwards, the event traverses upwards toward the root scope and calls all registered
548573
* listeners along the way. The event will stop propagating if one of the listeners cancels it.
549574
*
550-
* Any exception emmited from the {@link angular.scope.$on listeners} will be passed
575+
* Any exception emmited from the {@link angular.module.NG.$rootScope.Scope.$on listeners} will be passed
551576
* onto the {@link angular.service.$exceptionHandler $exceptionHandler} service.
552577
*
553578
* @param {string} name Event name to emit.
@@ -585,19 +610,20 @@ function $RootScopeProvider(){
585610

586611
/**
587612
* @ngdoc function
588-
* @name angular.scope.$broadcast
613+
* @name angular.module.NG.$rootScope.Scope#$broadcast
614+
* @methodOf angular.module.NG.$rootScope.Scope
589615
* @function
590616
*
591617
* @description
592618
* Dispatches an event `name` downwards to all child scopes (and their children) notifying the
593-
* registered {@link angular.scope.$on} listeners.
619+
* registered {@link angular.module.NG.$rootScope.Scope.$on} listeners.
594620
*
595621
* The event life cycle starts at the scope on which `$broadcast` was called. All
596-
* {@link angular.scope.$on listeners} listening for `name` event on this scope get notified.
622+
* {@link angular.module.NG.$rootScope.Scope.$on listeners} listening for `name` event on this scope get notified.
597623
* Afterwards, the event propagates to all direct and indirect scopes of the current scope and
598624
* calls all registered listeners along the way. The event cannot be canceled.
599625
*
600-
* Any exception emmited from the {@link angular.scope.$on listeners} will be passed
626+
* Any exception emmited from the {@link angular.module.NG.$rootScope.Scope.$on listeners} will be passed
601627
* onto the {@link angular.service.$exceptionHandler $exceptionHandler} service.
602628
*
603629
* @param {string} name Event name to emit.

0 commit comments

Comments
 (0)