Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to find out what is triggering change detection in Angular 2?

Tags:

angular

I recently released a new component and it seems to be triggering change detection multiple times a second:

  // some debugging code
  ngDoCheck() {
    console.log('DO_CHECK', new Date().toLocaleTimeString());
  }

Results:

enter image description here

I've yet to figure out what is triggering this.

Am I reading this output correctly? Change detection is being triggered multiple times a second?

Is there any good method for figuring out what is triggering change detection in an Angular 2 application?

like image 870
jcroll Avatar asked Apr 27 '17 14:04

jcroll


People also ask

What triggers change detection Angular?

By default, angular will run the change detector every time @Input() data is changed or modified. But with OnPush strategy, the change detector is only triggered if the data passed on @Input() has a new reference.

How Angular knows if any value change and how its updated in change detection?

Angular's change detection kicks in to propagate the changes; Change detection goes through every components in the component tree (from top to bottom) to check if the model it depends on changed; If Yes, it will update the component; Angular updates the component's view (DOM).

How does Angular 2 detect changes?

How is change detection implemented? Angular can detect when component data changes, and then automatically re-render the view to reflect that change.

Does Async pipe triggering change detection?

It means that the component with the async pipe will be marked for check every time a new value is emitted. And Angular will check the component next time it runs change detection even if the value hasn't changed.


1 Answers

The Angular DevTools for Chrome provide a profiler that will list all change detection events and will show the source for each event.

like image 57
slim Avatar answered Oct 26 '22 18:10

slim