This is the archived documentation for Angular v6. Please visit angular.io to see documentation for the current version of Angular.

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.

See more...

interface DoCheck { ngDoCheck(): void }
      
      interface DoCheck {
  ngDoCheck(): void
}
    

See also

Description

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, 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.

Methods

A callback method that performs change-detection, invoked after the default change-detector runs. See KeyValueDiffers and IterableDiffers for implementing custom change checking for collections.

ngDoCheck(): void
      
      ngDoCheck(): void
    

Parameters

There are no parameters.

Returns

void

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() { // ... } }
      
      @Component({selector: 'my-cmp', template: `...`})
class MyComponent implements DoCheck {
  ngDoCheck() {
    // ...
  }
}