Skip to content

Commit 3a62023

Browse files
zbjornsonmhevery
authored andcommitted
docs(LifecycleHooks): correct ngDoCheck description (#8807)
The current behavior is for ngDoCheck to supplement, not override, the default change detector. OnChanges will still be called when DoCheck is implemented (fixes #7307).
1 parent fa2ce81 commit 3a62023

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

modules/@angular/core/src/metadata/lifecycle_hooks.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,19 @@ export abstract class OnChanges { abstract ngOnChanges(changes: SimpleChanges);
130130
export abstract class OnInit { abstract ngOnInit(); }
131131

132132
/**
133-
* Implement this interface to override the default change detection algorithm for your directive.
133+
* Implement this interface to supplement the default change detection algorithm in your directive.
134134
*
135-
* `ngDoCheck` gets called to check the changes in the directives instead of the default algorithm.
135+
* `ngDoCheck` gets called to check the changes in the directives in addition to the default algorithm.
136136
*
137137
* The default change detection algorithm looks for differences by comparing bound-property values
138-
* by reference across change detection runs. When `DoCheck` is implemented, the default algorithm
139-
* is disabled and `ngDoCheck` is responsible for checking for changes.
138+
* by reference across change detection runs.
140139
*
141-
* Implementing this interface allows improving performance by using insights about the component,
142-
* its implementation and data types of its properties.
140+
* Note that a directive typically should not use both `DoCheck` and {@link OnChanges} to respond to
141+
* changes on the same input. `ngOnChanges` will continue to be called when the default change detector
142+
* detects changes, so it is usually unnecessary to respond to changes on the same input in both hooks.
143+
* Reaction to the changes have to be handled from within the `ngDoCheck` callback.
143144
*
144-
* Note that a directive should not implement both `DoCheck` and {@link OnChanges} at the same time.
145-
* `ngOnChanges` would not be called when a directive implements `DoCheck`. Reaction to the changes
146-
* have to be handled from within the `ngDoCheck` callback.
147-
*
148-
* Use {@link KeyValueDiffers} and {@link IterableDiffers} to add your custom check mechanisms.
145+
* You can use {@link KeyValueDiffers} and {@link IterableDiffers} to help add your custom check mechanisms.
149146
*
150147
* ### Example ([live demo](http://plnkr.co/edit/QpnIlF0CR2i5bcYbHEUJ?p=preview))
151148
*

0 commit comments

Comments
 (0)