24
24
* implemented in the same way as watch. Watch requires return of initialization function which
25
25
* are expensive to construct.
26
26
*/
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
+ */
27
37
function $RootScopeProvider ( ) {
28
38
this . $get = [ '$injector' , '$exceptionHandler' , '$parse' ,
29
39
function ( $injector , $exceptionHandler , $parse ) {
30
40
/**
31
41
* @ngdoc function
32
- * @name angular.scope
42
+ * @name angular.module.NG.$rootScope.Scope
33
43
*
34
44
* @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.)
38
49
*
39
50
* Here is a simple scope snippet to show how you can interact with the scope.
40
51
* <pre>
41
- var scope = angular.scope();
52
+ angular.injector(function($rootScope) {
53
+ var scope = $rootScope.$new();
42
54
scope.salutation = 'Hello';
43
55
scope.name = 'World';
44
56
@@ -55,12 +67,13 @@ function $RootScopeProvider(){
55
67
56
68
scope.$digest(); // fire all the watches
57
69
expect(scope.greeting).toEqual('Hello Misko!');
70
+ });
58
71
* </pre>
59
72
*
60
73
* # Inheritance
61
74
* A scope can inherit from a parent scope, as in this example:
62
75
* <pre>
63
- var parent = angular.scope() ;
76
+ var parent = $rootScope ;
64
77
var child = parent.$new();
65
78
66
79
parent.salutation = "Hello";
@@ -97,7 +110,8 @@ function $RootScopeProvider(){
97
110
98
111
/**
99
112
* @ngdoc property
100
- * @name angular.scope.$id
113
+ * @name angular.module.NG.$rootScope.Scope#$id
114
+ * @propertyOf angular.module.NG.$rootScope.Scope
101
115
* @returns {number } Unique scope ID (monotonically increasing alphanumeric sequence) useful for
102
116
* debugging.
103
117
*/
@@ -106,16 +120,17 @@ function $RootScopeProvider(){
106
120
Scope . prototype = {
107
121
/**
108
122
* @ngdoc function
109
- * @name angular.scope.$new
123
+ * @name angular.module.NG.$rootScope.Scope#$new
124
+ * @methodOf angular.module.NG.$rootScope.Scope
110
125
* @function
111
126
*
112
127
* @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()}.
117
132
*
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
119
134
* the scope and its child scopes to be permanently detached from the parent and thus stop
120
135
* participating in model change detection and listener notification by invoking.
121
136
*
@@ -160,16 +175,17 @@ function $RootScopeProvider(){
160
175
161
176
/**
162
177
* @ngdoc function
163
- * @name angular.scope.$watch
178
+ * @name angular.module.NG.$rootScope.Scope#$watch
179
+ * @methodOf angular.module.NG.$rootScope.Scope
164
180
* @function
165
181
*
166
182
* @description
167
183
* Registers a `listener` callback to be executed whenever the `watchExpression` changes.
168
184
*
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()}
171
187
* 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.)
173
189
* - The `listener` is called only when the value from the current `watchExpression` and the
174
190
* previous call to `watchExpression' are not equal. The inequality is determined according to
175
191
* {@link angular.equals} function. To save the value of the object for later comparison
@@ -180,15 +196,15 @@ function $RootScopeProvider(){
180
196
* limit is 100 to prevent infinity loop deadlock.
181
197
*
182
198
*
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,
184
200
* 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
186
202
* detected, be prepared for multiple calls to your listener.)
187
203
*
188
204
*
189
205
* # Example
190
206
<pre>
191
- var scope = angular.scope ();
207
+ var scope = angular.module.NG.$rootScope.Scope ();
192
208
scope.name = 'misko';
193
209
scope.counter = 0;
194
210
@@ -208,7 +224,7 @@ function $RootScopeProvider(){
208
224
*
209
225
*
210
226
* @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
212
228
* call to the `listener`.
213
229
*
214
230
* - `string`: Evaluated as {@link guide/dev_guide.expressions expression}
@@ -247,36 +263,39 @@ function $RootScopeProvider(){
247
263
248
264
/**
249
265
* @ngdoc function
250
- * @name angular.scope.$digest
266
+ * @name angular.module.NG.$rootScope.Scope#$digest
267
+ * @methodOf angular.module.NG.$rootScope.Scope
251
268
* @function
252
269
*
253
270
* @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
257
274
* firing. This means that it is possible to get into an infinite loop. This function will throw
258
275
* `'Maximum iteration limit exceeded.'` if the number of iterations exceeds 100.
259
276
*
260
277
* Usually you don't call `$digest()` directly in
261
278
* {@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
263
280
* {@link angular.directive directive}) will force a `$digest()`.
264
281
*
265
282
* 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()}
267
284
* with no `listener`.
268
285
*
269
286
* You may have a need to call `$digest()` from within unit-tests, to simulate the scope
270
287
* life-cycle.
271
288
*
272
289
* # Example
273
290
<pre>
274
- var scope = angular.scope() ;
291
+ var scope = ... ;
275
292
scope.name = 'misko';
276
293
scope.counter = 0;
277
294
278
295
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
+ });
280
299
expect(scope.counter).toEqual(0);
281
300
282
301
scope.$digest();
@@ -363,16 +382,17 @@ function $RootScopeProvider(){
363
382
364
383
/**
365
384
* @ngdoc function
366
- * @name angular.scope.$destroy
385
+ * @name angular.module.NG.$rootScope.Scope#$destroy
386
+ * @methodOf angular.module.NG.$rootScope.Scope
367
387
* @function
368
388
*
369
389
* @description
370
390
* 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
372
392
* scope and its children. Removal also implies that the current scope is eligible for garbage
373
393
* collection.
374
394
*
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}.
376
396
*
377
397
* The `$destroy()` is usually used by directives such as
378
398
* {@link angular.widget.@ng:repeat ng:repeat} for managing the unrolling of the loop.
@@ -391,7 +411,8 @@ function $RootScopeProvider(){
391
411
392
412
/**
393
413
* @ngdoc function
394
- * @name angular.scope.$eval
414
+ * @name angular.module.NG.$rootScope.Scope#$eval
415
+ * @methodOf angular.module.NG.$rootScope.Scope
395
416
* @function
396
417
*
397
418
* @description
@@ -400,7 +421,7 @@ function $RootScopeProvider(){
400
421
*
401
422
* # Example
402
423
<pre>
403
- var scope = angular.scope ();
424
+ var scope = angular.module.NG.$rootScope.Scope ();
404
425
scope.a = 1;
405
426
scope.b = 2;
406
427
@@ -421,7 +442,8 @@ function $RootScopeProvider(){
421
442
422
443
/**
423
444
* @ngdoc function
424
- * @name angular.scope.$evalAsync
445
+ * @name angular.module.NG.$rootScope.Scope#$evalAsync
446
+ * @methodOf angular.module.NG.$rootScope.Scope
425
447
* @function
426
448
*
427
449
* @description
@@ -430,7 +452,7 @@ function $RootScopeProvider(){
430
452
* The `$evalAsync` makes no guarantees as to when the `expression` will be executed, only that:
431
453
*
432
454
* - 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
434
456
* `expression` execution.
435
457
*
436
458
* Any exceptions from the execution of the expression are forwarded to the
@@ -448,15 +470,16 @@ function $RootScopeProvider(){
448
470
449
471
/**
450
472
* @ngdoc function
451
- * @name angular.scope.$apply
473
+ * @name angular.module.NG.$rootScope.Scope#$apply
474
+ * @methodOf angular.module.NG.$rootScope.Scope
452
475
* @function
453
476
*
454
477
* @description
455
478
* `$apply()` is used to execute an expression in angular from outside of the angular framework.
456
479
* (For example from browser DOM events, setTimeout, XHR or third party libraries).
457
480
* Because we are calling into the angular framework we need to perform proper scope life-cycle
458
481
* of {@link angular.service.$exceptionHandler exception handling},
459
- * {@link angular.scope .$digest executing watches}.
482
+ * {@link angular.module.NG.$rootScope.Scope .$digest executing watches}.
460
483
*
461
484
* ## Life cycle
462
485
*
@@ -475,11 +498,11 @@ function $RootScopeProvider(){
475
498
* Scope's `$apply()` method transitions through the following stages:
476
499
*
477
500
* 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.
479
502
* 2. Any exceptions from the execution of the expression are forwarded to the
480
503
* {@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.
483
506
*
484
507
*
485
508
* @param {(string|function())= } exp An angular expression to be executed.
@@ -501,11 +524,12 @@ function $RootScopeProvider(){
501
524
502
525
/**
503
526
* @ngdoc function
504
- * @name angular.scope.$on
527
+ * @name angular.module.NG.$rootScope.Scope#$on
528
+ * @methodOf angular.module.NG.$rootScope.Scope
505
529
* @function
506
530
*
507
531
* @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
509
533
* event life cycle.
510
534
*
511
535
* @param {string } name Event name to listen on.
@@ -535,19 +559,20 @@ function $RootScopeProvider(){
535
559
536
560
/**
537
561
* @ngdoc function
538
- * @name angular.scope.$emit
562
+ * @name angular.module.NG.$rootScope.Scope#$emit
563
+ * @methodOf angular.module.NG.$rootScope.Scope
539
564
* @function
540
565
*
541
566
* @description
542
567
* 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.
544
569
*
545
570
* 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.
547
572
* Afterwards, the event traverses upwards toward the root scope and calls all registered
548
573
* listeners along the way. The event will stop propagating if one of the listeners cancels it.
549
574
*
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
551
576
* onto the {@link angular.service.$exceptionHandler $exceptionHandler} service.
552
577
*
553
578
* @param {string } name Event name to emit.
@@ -585,19 +610,20 @@ function $RootScopeProvider(){
585
610
586
611
/**
587
612
* @ngdoc function
588
- * @name angular.scope.$broadcast
613
+ * @name angular.module.NG.$rootScope.Scope#$broadcast
614
+ * @methodOf angular.module.NG.$rootScope.Scope
589
615
* @function
590
616
*
591
617
* @description
592
618
* 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.
594
620
*
595
621
* 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.
597
623
* Afterwards, the event propagates to all direct and indirect scopes of the current scope and
598
624
* calls all registered listeners along the way. The event cannot be canceled.
599
625
*
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
601
627
* onto the {@link angular.service.$exceptionHandler $exceptionHandler} service.
602
628
*
603
629
* @param {string } name Event name to emit.
0 commit comments