3

How angular2 perform change detection default strategy ? I have gone through some post related with the change detection and got some details like 'angular2 creates change detector for every component'.

Now for instance If I've 4 components (comp1, comp2 comp3 & comp4) and I change comp4 property so change detection would be perform through all components or single component ?

Can you please provide some code tutorial link related above info ?

Sachet Gupta
  • 822
  • 5
  • 18
shubham AK
  • 292
  • 1
  • 3
  • 13
  • 1
    Welcome to StackOverflow. This question is off-topic on SO because it's about asking for external resources which is discouraged. For a direct answer it's quite broad. If you can make it more concrete it could be answered. "I change comp4 property" is not enough information. It also depends how these component are related (if there are any bindings, shared services, ...) Ideally you'd create a Plunker that demonstrates the situation and then ask concrete questions about it. Plunker provides a ready-to-use Angular 4 template. – Günter Zöchbauer Aug 21 '17 at 08:13

1 Answers1

1

Here is the detailed article that will help you understand change detection:

Also see this answer.

Now for instance If I've 4 components (comp1, comp2 comp3 & comp4) and I change comp4 property so change detection would be perform through all components or single component ?

If you change the comp4 property as a result of some async opertation like setTimeout, the change detection will run from root level component and down to children. So you will have change detection for all components.

If some of the components set ChangeDetectionStrategy.OnPush, they will be skipped if the input bindings haven't changed.

Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488