From 3a62023260e59dafcb57ec12c3be1e3643639347 Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Thu, 26 May 2016 10:27:42 -0700 Subject: [PATCH] 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). --- .../core/src/metadata/lifecycle_hooks.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/modules/@angular/core/src/metadata/lifecycle_hooks.ts b/modules/@angular/core/src/metadata/lifecycle_hooks.ts index 89672128c5..7fcb70a8c1 100644 --- a/modules/@angular/core/src/metadata/lifecycle_hooks.ts +++ b/modules/@angular/core/src/metadata/lifecycle_hooks.ts @@ -130,22 +130,19 @@ export abstract class OnChanges { abstract ngOnChanges(changes: SimpleChanges); export abstract class OnInit { abstract ngOnInit(); } /** - * Implement this interface to override the default change detection algorithm for your directive. + * Implement this interface to supplement the default change detection algorithm in your directive. * - * `ngDoCheck` gets called to check the changes in the directives instead of the default algorithm. + * `ngDoCheck` gets called to check the changes in the directives in addition to the default algorithm. * * The default change detection algorithm looks for differences by comparing bound-property values - * by reference across change detection runs. When `DoCheck` is implemented, the default algorithm - * is disabled and `ngDoCheck` is responsible for checking for changes. + * by reference across change detection runs. * - * Implementing this interface allows improving performance by using insights about the component, - * its implementation and data types of its properties. + * Note that a directive typically should not use both `DoCheck` and {@link OnChanges} to respond to + * changes on the same input. `ngOnChanges` will continue to be called when the default change detector + * detects changes, so it is usually unnecessary to respond to changes on the same input in both hooks. + * Reaction to the changes have to be handled from within the `ngDoCheck` callback. * - * Note that a directive should not implement both `DoCheck` and {@link OnChanges} at the same time. - * `ngOnChanges` would not be called when a directive implements `DoCheck`. Reaction to the changes - * have to be handled from within the `ngDoCheck` callback. - * - * Use {@link KeyValueDiffers} and {@link IterableDiffers} to add your custom check mechanisms. + * You can use {@link KeyValueDiffers} and {@link IterableDiffers} to help add your custom check mechanisms. * * ### Example ([live demo](http://plnkr.co/edit/QpnIlF0CR2i5bcYbHEUJ?p=preview)) *