Can not understand ngDoCheck method in lifecycle Hooks for component

633 views Asked by At

From Angular documentation:

Detect and act upon changes that Angular can't or won't detect on its own.

Called during every change detection run, immediately after ngOnChanges and ngOnInit.

How this method can be called during every change detection run if angular can't or won't detect on its own?

Can somebody explain and give an example?

1

There are 1 answers

0
Günter Zöchbauer On BEST ANSWER

Angular calls it when change detection is run instead of or in addition to doing actual change detection of bindings in your component ("instead of" if change detection is disabled for your component) so you can do some custom checks or notifications in your custom code. You can check the source of NgClass or NgFor for examples. Your custom change detection might be more efficient than Angulars default CD.