Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - Prevent Change Detection

Tags:

I have a setInterval() function in a component class that fires off every 1/10 of a second. All it does is update a d3 graph and does not touch any angular bindings.

By default setInterval() triggers the change detection in angular from the root node.

Is there a way to run the setInterval() function without triggering any change detection?

I don't need the rest of the app to update itself since I know this only affects the graph and d3 is the only one responsible for the updating the graph.

like image 668
Nik Avatar asked Apr 06 '17 14:04

Nik


People also ask

How do I turn off change detection?

Click on "Enable Change Detection" from the given list. Select "Enable" or "Disable" operation based on your requirement. If you select Disable, skip to the last step.

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.

What triggers Angular change detection?

Angular runs its change detection mechanism periodically so that changes to the data model are reflected in an application's view. Change detection can be triggered either manually or through an asynchronous event (for example, a user interaction or an XMLHttpRequest completion).

What does ChangeDetectorRef detectChanges () do?

detectChanges()link Checks this view and its children. Use in combination with detach to implement local change detection checks.


1 Answers

You have to run it outside of angular. Take a look at this answer to a similar question.

https://stackoverflow.com/a/39626378/1710501

like image 95
camccar Avatar answered Sep 24 '22 10:09

camccar