DoCheck
A lifecycle hook that invokes a custom change-detection function for a directive,
in addition to the check performed by the default change-detector on the input
bindings for this directive usage in the parent template. Note that this hook is
invoked even when the directive's own change detection is skipped (e.g., with
the OnPush change detection strategy). Developers might use this hook to
implement a custom change detection strategy for some of the inputs.
ngDoCheck
voidA callback method that performs change-detection, invoked
after the default change-detector has checked the directive's input
bindings in the parent template.
See KeyValueDiffers and IterableDiffers for implementing
custom change checking for collections.
voidDescription
A lifecycle hook that invokes a custom change-detection function for a directive,
in addition to the check performed by the default change-detector on the input
bindings for this directive usage in the parent template. Note that this hook is
invoked even when the directive's own change detection is skipped (e.g., with
the OnPush change detection strategy). Developers might use this hook to
implement a custom change detection strategy for some of the inputs.
The default change-detection algorithm looks for differences by comparing bound-property values by reference across change detection runs. You can use this hook to check for and respond to changes by some other means.
When the default change detector detects changes to the directive's input bindings,
it invokes ngOnChanges() if supplied, regardless of whether you perform
additional change detection.
Typically, you should not use both DoCheck and OnChanges to respond to
changes on the same input.
Usage Notes
The following snippet shows how a component can implement this interface to invoke it own change-detection cycle.
@Component({
selector: 'my-cmp',
template: `...`,
})
class MyComponent implements DoCheck {
ngDoCheck() {
// ...
}
}
For a more complete example and discussion, see Defining custom change detection.