Skip to content

Commit d630d5b

Browse files
committed
docs(change_detection): document LifeCycle
1 parent 7cac7c5 commit d630d5b

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

modules/angular2/src/core/life_cycle/life_cycle.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ import {ExceptionHandler} from 'angular2/src/core/exception_handler';
55
import {isPresent} from 'angular2/src/facade/lang';
66

77
/**
8+
* Provides access to explicitly trigger change detection in an application.
9+
*
10+
* By default, [Zone] triggers change detection in Angular on each virtual machine (VM) turn. When testing, or in some
11+
* limited application use cases, a developer can also trigger change detection with the `lifecycle.tick()` method.
12+
*
13+
* Each Angular application has a single `LifeCycle` instance.
14+
*
15+
* # Example
16+
*
17+
* This is a contrived example, since the bootstrap automatically runs inside of the [Zone], which invokes
18+
* `lifecycle.tick()` on your behalf.
19+
*
20+
* ```javascript
21+
* bootstrap(MyApp).then((ref:ComponentRef) => {
22+
* var lifeCycle = ref.injector.get(LifeCycle);
23+
* var myApp = ref.instance;
24+
*
25+
* ref.doSomething();
26+
* lifecycle.tick();
27+
* });
28+
* ```
29+
*
30+
*
831
* @exportedAs angular2/change_detection
932
*/
1033
@Injectable()
@@ -33,6 +56,16 @@ export class LifeCycle {
3356
});
3457
}
3558

59+
/**
60+
* Invoke this method to explicitly process change detection and its side-effects.
61+
*
62+
* In development mode, `tick()` also performs a second change detection cycle to ensure that no further
63+
* changes are detected. If additional changes are picked up during this second cycle, bindings in the app have
64+
* side-effects that cannot be resolved in a single change detection pass. In this case, Angular throws an error,
65+
* since an Angular application can only have one change detection pass during which all change detection must
66+
* complete.
67+
*
68+
*/
3669
tick() {
3770
this._changeDetector.detectChanges();
3871
if (this._enforceNoNewChanges) {

0 commit comments

Comments
 (0)