Skip to content

Commit 9d2d674

Browse files
committed
docs(change_detection): add docs to change detection exceptions
1 parent 7470ad1 commit 9d2d674

File tree

1 file changed

+61
-7
lines changed

1 file changed

+61
-7
lines changed

modules/angular2/src/core/change_detection/exceptions.ts

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,35 @@ import {BaseException, WrappedException} from "angular2/src/core/facade/exceptio
33
/**
44
* An error thrown if application changes model breaking the top-down data flow.
55
*
6-
* Angular expects that the data flows from top (root) component to child (leaf) components.
7-
* This is known as directed acyclic graph. This allows Angular to only execute change detection
8-
* once and prevents loops in change detection data flow.
9-
*
106
* This exception is only thrown in dev mode.
7+
*
8+
* <!-- TODO: Add a link once the dev mode option is configurable -->
9+
*
10+
* ### Example
11+
*
12+
* ```typescript
13+
* @Component({selector: 'parent'})
14+
* @View({
15+
* template: `
16+
* <child [prop]="parentProp"></child>
17+
* `,
18+
* directives: [forwardRef(() => Child)]
19+
* })
20+
* class Parent {
21+
* parentProp = "init";
22+
* }
23+
*
24+
* @Directive({selector: 'child', properties: ['prop']})
25+
* class Child {
26+
* constructor(public parent: Parent) {}
27+
*
28+
* set prop(v) {
29+
* // this updates the parent property, which is disallowed during change detection
30+
* // this will result in ExpressionChangedAfterItHasBeenCheckedException
31+
* this.parent.parentProp = "updated";
32+
* }
33+
* }
34+
* ```
1135
*/
1236
export class ExpressionChangedAfterItHasBeenCheckedException extends BaseException {
1337
constructor(exp: string, oldValue: any, currValue: any, context: any) {
@@ -19,11 +43,39 @@ export class ExpressionChangedAfterItHasBeenCheckedException extends BaseExcepti
1943
/**
2044
* Thrown when an expression evaluation raises an exception.
2145
*
22-
* This error wraps the original exception, this is done to attach expression location information.
46+
* This error wraps the original exception to attach additional contextual information that can
47+
* be useful for debugging.
48+
*
49+
* ### Example ([live demo](http://plnkr.co/edit/2Kywoz?p=preview))
50+
*
51+
* ```typescript
52+
* @Directive({selector: 'child', properties: ['prop']})
53+
* class Child {
54+
* prop;
55+
* }
56+
*
57+
* @Component({
58+
* selector: 'app'
59+
* })
60+
* @View({
61+
* template: `
62+
* <child [prop]="field.first"></child>
63+
* `,
64+
* directives: [Child]
65+
* })
66+
* class App {
67+
* field = null;
68+
* }
69+
*
70+
* bootstrap(App);
71+
* ```
72+
*
73+
* You can access the original exception and stack through the `originalException` and
74+
* `originalStack` properties.
2375
*/
2476
export class ChangeDetectionError extends WrappedException {
2577
/**
26-
* Location of the expression.
78+
* Information about the expression that triggered the exception.
2779
*/
2880
location: string;
2981

@@ -36,7 +88,9 @@ export class ChangeDetectionError extends WrappedException {
3688
/**
3789
* Thrown when change detector executes on dehydrated view.
3890
*
39-
* This is angular internal error.
91+
* This error indicates a bug in the framework.
92+
*
93+
* This is an internal Angular error.
4094
*/
4195
export class DehydratedException extends BaseException {
4296
constructor() { super('Attempt to detect changes on a dehydrated detector.'); }

0 commit comments

Comments
 (0)