Angular2 component ngDoCheck is endlessly executed

4.1k Views Asked by At

I have a simple angular2 component that contains only an ag-grid component with some data bind to it.

My component implement the DoCheck and the ngDoCheck method is implement in the component.

export class AppComponent implements DoCheck 
{
    ngDoCheck() {
        console.log('do check..');
    }
} 

I have realized that the ngDoCheck function is always running endlessly.

Any explanation about this issue.

2

There are 2 best solutions below

3
Valex On

This hook is called with enormous frequency — after every change detection cycle no matter where the change occurred.

Is a really dirty cycle, in fact even angular itself is suggesting to use more proper way to implement custom checks.

https://angular.io/docs/ts/latest/api/core/index/DoCheck-class.html

1
Dzmitry Vasilevsky On

In my case ngAfterViewChecked was called endlessly because of sentry.js which do monkey patching of console.log which triggers Change Detection. I pulled off half of my hair till noticed that code below causes loop because of sentry.

ngAfterViewChecked () {

    console.log('Rendered');

}